[Python-3000] Mini Path object

Jim Jewett jimjjewett at gmail.com
Sun Nov 26 20:13:57 CET 2006


On 11/26/06, Mike Orr <sluggoster at gmail.com> wrote:
> On 11/26/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> > On 11/26/06, Mike Orr <sluggoster at gmail.com> wrote:
> > > I tried to make a separate PathAlgebra class and
> > > FSPath class, but it got so unweildly to use I made
> > > the latter a subclass.  They're now called
> > > PathName and Path.

> > This makes sense to me.  An FSPath without path
> > algebra is basically a "directory listing"

> It's a single path, actually,

Fair enough.

> upon which you can call filesystem operations.
>     p.mkdir(), p.copytree(), p.read_file(), p.readlink(), p.listdir()

So if it doesn't happen to point to a directory, you can either ask it
for a different Path (the result of readlink) or open it
(read_file)...

> What you *can't* do is extract/alter the pathname
> itself using FSPath operations.
>     p.ext, p + ".gz", p.expand_user()    # Error!  Use p.path.ext instead.

I had thought that Path objects were immutable, and so these would
produce new isntances.

> > C: without a slash is effectively a mount point into
> >  the current directory.

> That's what I always thought "C:foo" is.  But Glyph
> said it's more complicated than that:

Most of the exceptions were things like the CON special file.  These
make the windows (or DOS) filesystem wierd, but they aren't really
affected by C: vs C:\

CON, C:\dir1\CON, C:CON, and .\con all refer to the same special file.

-jJ


More information about the Python-3000 mailing list