When I run any Python script, I would like to see the script's filename appear in the Windows command line window's titlebar. For example, if I run a script called "mytest.py
", I want to see "mytest
" in the titlebar. I would like this to be automatic, so I don't have to add code to every one of my scripts.
Currently I'm attempting to do this with sitecustomize.py
, because when Python is run, including from double-clicking a Python script, sitecustomize
is imported before the script runs.
I've tried getting __main__
's __file__
and sys.argv
, but sitecustomize
doesn't see either:
file sitecustomize.py
:
import __main__, sys
print "hasattr __main__.__file__:", hasattr(__main__, "__file__")
print "hasattr sys.argv:", hasattr(sys, "argv")
print "-" * 60
file mytest.py
:
import sys
print "__file__ is:", __file__
print "sys.argv is:", sys.argv
raw_input() # don't end the script immediately
output:
hasattr __main__.__file__: False
hasattr sys.argv: False
------------------------------------------------------------
__file__ is: C:\Documents and Settings\Owner\Desktop\mytest.py
sys.argv is: ['C:\\Documents and Settings\\Owner\\Desktop\\mytest.py']