Saturday, December 1, 2007

How to get program's directory in python?

import os

path = os.path.dirname(__file__) to get the path of .py file.

os.path.dirname returns the directory component of a pathname, __file__ is the full path of .py file.

os.path is a useful module, see the doc:
http://docs.python.org/lib/module-os.path.html

No comments: