how to get file name of the running .py file

Larry Bates larry.bates at websafe.com
Wed Aug 23 18:52:07 EDT 2006


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



More information about the Python-list mailing list