Larry Bates wrote:
>> How to get the name of the running .py file like the macro _FILE_ in C?
> 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])
except that __FILE__ is the name of the current source fil
Jason Jiang wrote:
> Hi,
>
> How to get the name of the running .py file like the macro _FILE_ in C?
There are many ways--IMO the easiest is with __file__:
>>> print __file__
/home/bill/.pystart
>>>
[tmp]$ cat foo.py
#!/usr/bin/env python
print "The name of the file is:%s"%__file__
[tmp]$ ./foo
Thank you guys.
Jason
"Simon Forman" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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
>> impor
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.
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
--
http://mail.python
Hi,
How to get the name of the running .py file like the macro _FILE_ in C?
Thanks.
Jason
--
http://mail.python.org/mailman/listinfo/python-list