Name of the Script
Steve Purcell
stephen_purcell at yahoo.com
Mon Mar 5 11:18:13 EST 2001
Paul Moore wrote:
> On Mon, 5 Mar 2001 16:17:38 +0100 , Pearu Peterson <pearu at cens.ioc.ee>
> wrote:
> >--- a.py ---
> >import os,sys
> >print os.path.abspath(sys.argv[0])
> >---
> >might be what you want.
>
> Close, but not quite...
>>> def current_module_path():
... import os, sys
... try:
... path = sys.modules[__name__].__file__
... except AttributeError:
... path = sys.argv[0]
... return path and os.path.join(os.getcwd(), path) or None
...
>>>
Then, in an interactive session:
>>> `current_module_path()`
'None'
And in 'a.py':
'/home/steve/a.py'
-Steve
--
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Get servlets at http://pyserv.sourceforge.net/
"Even snakes are afraid of snakes." -- Steven Wright
More information about the Python-list
mailing list