Filename type (Was: Re: finding file size)

Gerrit Holl gerrit at
Sun Jan 4 14:43:37 CET 2004

Peter Otten wrote:
> While a string is the default that you read from files and GUI widgets, a
> filename will never be.

I'm not so sure about that. A GUI where a file is selected from the list
could very well return a Path object - it won't for a while, of course,
but that's a different issue. But I agree that is often isn't. Just as
an integer is not something you read from a file, etc. 

> So expect to replace e. g.
> os.path.exists(somestring) 
> with 
> os.filename(somestring).exists()
> which is slightly less compelling than somefile.exists().

I would rather read:

which is better than os.filename(somestring).exists() and, IMO, better
than os.path.exists(somestring). I think path should be a builtin.

> Are unicode filenames something we should care about?

That's a difficult issue. I don't know how to solve that. 

> Should filename really be a subclass of str? I think somepath[-1] could
> return the name as well.

It could. But I don't think it should. This would mean that the index of
a path returns the respective directories. Explicit is better than
implicit: somepath[-1] is not very explicit as being a basename.

> Should files and directories really be of the same class?

Directories could be a subclass, with some more features. But...

> These to me all seem real questions and at that point I'm not sure whether a
> filename class that looks like a light wrapper around os.path (even if you
> expect os.path to be implemented in terms of filename later) is the best
> possible answer.

...questions exist to be answered. I don't claim to know all answers,
but I think OO-ifying os.path is a good thing. How - that's another
issue, which is PEP-worthy.

>From earlier discussions, I get the impression that most people are
sympathic about OO-ifying os.path but that people don't agree in how to
do it. If we can agree on that, the only thing we need to do is
upgrading the BDFL's judgement from lukewarm to liking :)

I've written a Pre-PEP at:
It is very unfinished but it is a rough draft. Comments welcome.


132. If the "finger is pointed" at a man's wife about another man, but
she is not caught sleeping with the other man, she shall jump into the
river for her husband.
          -- 1780 BC, Hammurabi, Code of Law
Asperger's Syndrome - a personal approach:

More information about the Python-list mailing list