Finding name of running script

M.E.Farmer mefjr75 at hotmail.com
Sun Apr 17 21:57:34 EDT 2005


runes wrote:
> Thanks!
>
> That's os.path.basename() I guess. It's better, but still complex.

Yea murphy's typo ;)

> I have a
> _nof_ = argv[0].split(sep)[-1]  in my script template and use it
under
> the usage() function to tell what the script does, like:
> "cf.py counts files in directory or directory structure"
>
> If I change the filename, I want it to be automatically reflected
when
> running the script. That's the motivation.

Generally I do it the very same way just spell it different.
os.path.basename(sys.argv[0])

> I have the feeling that I came a cross some very simple way to
extract
> the filename, but I can't find my mental note ;-)
Maybe you found some black magic ;)
M.E.Farmer




More information about the Python-list mailing list