[Tutor] Errno 9
imonthejazz
imonthejazz at googlemail.com
Thu Feb 28 15:56:41 CET 2008
I think my problem was naming of the files, changed them and its fine now.
Man, i feel stupid.
When I have finished my project i'll share it with you guys!
On 28/02/2008, Kent Johnson <kent37 at tds.net> wrote:
>
> imonthejazz wrote:
> > Hi All,
> >
> > I am trying to read a line in a file then split the words in the line
> up.
> >
> > This is what i thought would work:
> >
> > # filearray.py
> >
> > import string
> >
> > # THE FOLLOWING FOUR LINE ARE THE CORRECT START TO THE PROGRAM,
> > # THE SIXTH AND SEVENTH LINES ARE ONLY FOR QUICK TEST PURPOSE!!!
> > infilename = raw_input("What file would you like to re-arrange?: ")
> > outfilename = raw_input("Where would you like to save to array?: ")
> > infile = open(infilename, 'r')
> > infile = open(outfilename, 'w')
>
>
> outfile would be a better name!
>
>
> >
> > #infile = open("G:\gnet.nmap", 'r')
> > #infile = open("G:\work2.txt", 'w')
> >
> > # process each line
> > for line in infile.readlines():
> > words = string.split(line)
> > print words
>
>
> Note you haven't written anything to outfile yet; print will go to the
> console. I'm not sure what you do want to write so I won't suggest
> anything.
>
>
> > # save and close files
> > infile.close()
> > infile.close()
>
>
> I guess this is line 16; you are closing the same file twice. Should be
> outfile.close()
>
>
> > But i get an "IO Error: [Errno 9] Bad file descriptor" on line 16.
>
>
> It would help to see the traceback, it includes the line with the error
> so we don't have to guess which is line 16.
>
>
> Kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080228/c1143785/attachment.htm
More information about the Tutor
mailing list