[Tutor] Locating directory of script?

Brian van den Broek broek at cc.umanitoba.ca
Thu Jan 12 07:56:03 CET 2006


Liam Clarke said unto the world upon 12/01/06 12:32 AM:
> 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

Hey Liam,

 >>> import this
The Zen of Python, by Tim Peters

<snip the wisdom>
 >>> this.__file__
'/usr/lib/python2.4/this.pyc'
 >>>

HTH,

Brian vdB


More information about the Tutor mailing list