Home     My Faqts     Contributors     About     Help    

faqts : Computers : Programming : Languages : Python

FAQTs repaired & updated!
Thanks for your patience...
Entry Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

7 of 7 people (100%) answered Yes
Recently 4 of 4 people (100%) answered Yes

How can I get my _full_ program name (eg. "mylongpythonscript.py") under eg. NT? sys.argv[0] gives me the truncated MS-DOS style, "MYLONG~1.PY" etc.

Oct 12th, 2000 00:48

Jon Nicoll, unknown unknown
Alex Martelli


This seems to work in my setup (2.0b2, Win98):
import sys
try: raise RuntimeError
except:
    x=sys.exc_info()[2]
    print x.tb_frame.f_code.co_filename
Placing this in alongfilename.py and running
    python alongfilename.py
results in the expected output:
alongfilename.py
##################################################
# Under (NT4, Python v1.5.2), the above also gives
# the 'short' form for me.
# This is a bit more Win32 specific, but works for my environment
import sys
import win32api
print win32api.FindFiles(sys.argv[0])[0][8]



© 1999-2004 Synop Pty Ltd