I'm an idiot

Beej Jørgensen beej at piratehaven.org
Fri Jun 28 21:24:07 EDT 2002


In article <Xns923BB72B1BAF7davidgriswold1netsca at 204.127.202.16>,
David  <david_griswold1 at yahoo.com> wrote:
>Any help would be appreciated.

Ok, I'm no pro and don't have the manuals in front of me, so I hope I
don't lead you too astray here:

>f=open('c:\\temp\\temp.txt', 'r')
>g=open('c:\\temp\\temp1.txt', 'w')
>while 1:
>    try:
>        s=f.readline
             ^^^^^^^^

This is a method, so I think it should be "f.readline()"

>        g.write(s.split())

Er, did you mean strip()?  And maybe you have to use String.strip(s),
but I can't remember.

>    except IOError:
>        break

Close--but I don't believe readline() throws an exception on EOF;
instead it just returns "".

>g.close
>f.close

So something like this:

    while 1:
        s = f.readline()
        if s == "": break
        g.write(String.strip(s))  # or s.strip(), if that doesn't work

Sorry if I hosed something here, but maybe it'll be enough to get you
going even if the info isn't entirely accurate.

-Beej




More information about the Python-list mailing list