[Tutor] Locating directory of script?

Liam Clarke ml.cyresse at gmail.com
Thu Jan 12 07:32:58 CET 2006


Hi all,

Let's say I have a script called bob.py in a directory called
c:\pythonstuff, which is in my PATH env_var, and python is also in my
PATH, and from a completely different directory I call "python bob.py"
is there a right way to determine what directory bob.py resides in?

So far I've found that

import inspect

class Foo:
	pass

sourceP = inspect.getsourcefile(Foo)

works, but I'm not too sure how resilient that is...

Regards,

Liam Clarke


More information about the Tutor mailing list