Adding a __filename__ predefined attribute to 2.5?

Stefan Rank stefan.rank at ofai.at
Wed Oct 12 04:30:15 EDT 2005


on 12.10.2005 10:02 Diez B. Roggisch said the following:
> Rune Strand wrote:
> 
>>Currently I have this in my scripts:
>>__filename__ = __file__.replace('\\', '/').rsplit('/', 1)[-1]
> 
> This is neither platform independent nor less "overhead". This is:
> 
> import os
> __filname__ = os.path.split(__file__)[-1]
> 

I would say that::

   import os
   filename = os.path.basename(__file__)

is even more explicit.

And with one of the several existing 'path' modules it would be::

   from path import path
   filename = path(__file__).basename


I am sorry if I missed this on this list,
but was there a decision on the idea of including an object-oriented
path class in the standard library?

cheers,
stefan




More information about the Python-list mailing list