views:

108

answers:

1

How do I find out the current runtime directory from within a Python script?

+4  A: 

Use os.getcwd. This will tell you the current working directory. If you create a new file with

fp = open('a.txt', 'w')

then a.txt will be created in the current working directory. Use os.chdir to change the working directory, if needed.

Martin Geisler