[Tutor] odd behavior when renaming a file
wprins at gmail.com
Wed May 9 21:55:30 CEST 2012
On 9 May 2012 20:26, Joel Goldstick <joel.goldstick at gmail.com> wrote:
> import os
> def pre_process():
> if os.path.isfile('revelex.csv'):
> os.rename('revelex.csv', 'revelex.tmp')
> print "Renamed ok"
> print "Exiting, no revelex.csv file available"
> out_file = open('revelex.csv', 'w')
> # etc.
> if __name__ == '__main__':
> When I run the code above it works file if run from the file. But
> when I import it and run it from another file it renames the file but
> then prints "Exiting, no revelex.csv file available"
Can you post where/how you call this from another file? Anyway, it sounds
like the pre_process() routine is being called twice, somehow. On the
first call the file is renamed. Then on the second call, of course the
file is not there anymore (as it's been renamed) and thus it prints the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor