Filename type (Was: Re: finding file size)

Peter Otten __peter__ at web.de
Sat Jan 3 07:14:53 EST 2004


Gerrit Holl wrote:

> I propose to add a "filename" type to Python.

> A different solution to this problem would be to introduce "filename"
> type to Python, a subclass of str. The "name" attribute of file would be
> of this type. This type would inherit a lot of os.path stuff: getsize
> becomes simpler, more readable, and more object oriented, as do other
> os.path functions. I think the alternatives look a lot more prety:

> OLD                                         NEW
> os.path.realpath(fn)                        fn.realpath()
> os.path.getmtime(fp.name)                   fp.name.getmtime()
> os.path.ismount(os.path.dirname(fp.name))   fp.name.dirname().ismount()
> 
> It's more beatiful, simpler, flatter (#3), practical, obvious, easy.

You might have a look at 

http://mail.python.org/pipermail/python-list/2002-June/108425.html

http://members.rogers.com/mcfletch/programming/filepath.py

has an implementation of your proposal by Mike C. Fletcher. I think both
filename class and os.path functions can peacefully coexist.


Peter






More information about the Python-list mailing list