how to get file name of the running .py file

Jason Jiang jiangnutao at gmail.com
Wed Aug 23 21:26:55 EDT 2006


Thank you guys.

Jason

"Simon Forman" <rogue_pedro at yahoo.com> wrote in message 
news:1156377386.047314.216020 at i3g2000cwc.googlegroups.com...
> 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
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 






More information about the Python-list mailing list