[Tutor] Adjusting a file
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 26 Aug 2002 17:13:06 +0100
> problem, when I run the script below, I get a syntax error
> the line after the except statement.
Not sure what that is but I think you have another problem...
> import os, time
>
> try:
> menu=open('C:/Python22/Menu.txt','r')
> outf=open('C:/Python22/Menu.txt','w')
I think this one should be "Menu.tmp" - otherwise you'll
stamp all over the file you are reading - not a good idea!
> os.rename('C:/Python22/Menu.txt', 'C:/Python22/Menu.bak')
> os.rename('C:/Python22/Menu.tmp', 'C:/Python22/Menu.txt')
And this line only makes sense if your new ffile is Menu.tmp...
> except:
> print 'ERROR: Failed to create new menu'
Hmm, The except could mean several things aside from that
but I guess it illustrates the idea OK. I can't see anything
that would cause a syntax error...
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld