[Tutor] odd behavior when renaming a file
joel.goldstick at gmail.com
Thu May 10 18:59:56 CEST 2012
On Wed, May 9, 2012 at 5:21 PM, Peter Otten <__peter__ at web.de> wrote:
> Joel Goldstick 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"
> print os.getcwd()
> to your code, you are probably in the wrong directory.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
Thanks for the hint. I am in the right directory, but I failed to
notice that I renamed the file before I entered my function.
Funny how a night of sleep can make dumb mistakes pop out.
More information about the Tutor