Adding a __filename__ predefined attribute to 2.5?
Steve Holden
steve at holdenweb.com
Wed Oct 12 03:21:32 EDT 2005
Rune Strand wrote:
> Is it an idea to include a new __filename__ predefined attribute to
> 2.5, so that __file__ contains the entire path to the module, and
> __filename__ only the name of the module?
>
> For instance it's useful to include a not-static reference to the
> filename in a scripts usage() section and it's cumbersome to extract
> the filename or to do module imports just to parse it.
>
No. It's not usually a good idea to remove complexity from your program
by adding it (where most of the time it's not needed) to the underlying
system. Here's a clue as to how you might do without __file__ altogether:
sholden at bigboy ~/Projects/Python
$ cat test78.py
import sys
print sys.argv
sholden at bigboy ~/Projects/Python
$ python test78.py can we say live with it?
['test78.py', 'can', 'we', 'say', 'live', 'with', 'it?']
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list