how to get file name of the running .py file

Simon Forman rogue_pedro at yahoo.com
Wed Aug 23 19:56:26 EDT 2006


Larry Bates wrote:
> Jason Jiang wrote:
> > Hi,
> >
> > How to get the name of the running .py file like the macro _FILE_ in C?
> >
> > Thanks.
> > Jason
> >
> >
> >
> import os
> import sys
> print sys.argv[0]
>
> or if you just want the script and not the full path
>
> print os.path.basename(sys.argv[0])
>
> -Larry Bates

Also, check out:
http://groups.google.ca/group/comp.lang.python/browse_frm/thread/712572b3c2f2cb13

Peace,
~Simon




More information about the Python-list mailing list