Python Forum
What am I doing wrong?
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What am I doing wrong?
#9
You are looking better. You still have a file named 'file', which you should change. I would take the opening of file2 out of the loop. You are currently opening it every time you write to it. You don't need to do that. Just open it once, and then close it (file2.close()) after the loop when you have finished writing to it.

Did you make a test file of just years with no text? That will tell you if you are getting anywhere. If it works on that easy file, then you are ready to work on the extra text.

The extra text you can probably deal with using the split method of strings. line.split() will break line into a list of words based on white space (spaces and tabs). Then you can check the first word with the isdigit method. word.isdigit() will be true if all the characters in the word are numbers. You just need to watch out for empty lines. The split method will give you an empty list for a blank line.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
What am I doing wrong? - by forumer444 - Sep-15-2017, 08:39 PM
RE: What am I doing wrong? - by Larz60+ - Sep-15-2017, 09:01 PM
RE: What am I doing wrong? - by ichabod801 - Sep-15-2017, 09:01 PM
RE: What am I doing wrong? - by forumer444 - Sep-15-2017, 09:32 PM
RE: What am I doing wrong? - by ichabod801 - Sep-15-2017, 09:04 PM
RE: What am I doing wrong? - by nilamo - Sep-15-2017, 09:30 PM
RE: What am I doing wrong? - by ichabod801 - Sep-15-2017, 10:59 PM
RE: What am I doing wrong? - by forumer444 - Sep-16-2017, 03:24 AM
RE: What am I doing wrong? - by ichabod801 - Sep-16-2017, 01:24 PM
RE: What am I doing wrong? - by forumer444 - Sep-16-2017, 10:09 PM
RE: What am I doing wrong? - by ichabod801 - Sep-17-2017, 01:27 AM
RE: What am I doing wrong? - by forumer444 - Sep-17-2017, 11:01 PM
RE: What am I doing wrong? - by ichabod801 - Sep-18-2017, 03:21 AM
RE: What am I doing wrong? - by forumer444 - Sep-20-2017, 12:47 AM
RE: What am I doing wrong? - by ichabod801 - Sep-20-2017, 01:24 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020