PRE-PEP: new Path class

From: John Roth (newsgroups_at_jhrothjr.com)
Date: 01/05/04


Date: Mon, 5 Jan 2004 10:06:59 -0500

I'm adding a thread for comments on Gerrit Holl's pre-pep, which
can be found here:

http://tinyurl.com/2578q

Frankly, I like the idea. It's about time that all of the file
and directory stuff in the os module got objectified
properly (or at least with some semblance of OO propriety!)

In the issues section:

1) Should path be a subclass of str?

No. Outside of the difficulty of deciding whether it's a
subclass of single byte or unicode strings, it's a pure
and simple case of Feature Envy. Granted, there will
be times a developer wants to use string methods, but
the most common operations should be supported directly.

2) virtual file system extensibility.

No opinion at this time. I'd like to see a couple
of attempts at an implementation first before
settling on a single design.

3) Should the / operator map joinpath.

I agree. No way. In the first place, that's a unixism
(Windows uses \, the Mac uses :) In the second
place it doesn't fit the common use of /, which is
to divide (separate) things. If we want an operator
for join (not a bad idea) I'd suggest using '+'. String
already overloads it for concatenation, and as I said
above, I'd just as soon *not* have this be a subclass
of string.

4) Should path expose an iterator for listdir(?)

I don't see why not, as long as the path is to a
directory.

5) Should == operator be the same as os.path.samefile()?

Why not...

6) Path.open()?

Of course.

7) Should the various gettime methods return Datetime
objects.

Of course.

8) Touch method?

Of course.

9) Current OS constants?

What are they? Are we talking about the four
constants in the access() function, or about something
else?

10) Commonprefix, walk and sameopenfile?

Commonprefix should be a string or list method,
it doesn't fit here.

walk is a nice function, but it should be redone to
use the visitor pattern directly, with different method
names for files, directories and whatever else a
particular file system has in it's warped little mind.

sameopenfile doesn't belong in the os.path module
in the first place. It belongs in the os module under
6.1.3 - File Descriptor Operations.

11) rename join and split.

I wouldn't bother. Since I'm against making it a
subclass of str(), the issue doesn't arise.

12) Should == compare file sizes.

No. Might have a method to do that.

13) chdir, chmod, etc?

No. This has nothing to do with pathname.

14. Unicode filenames

Have to have them on Windows and probably
on the Mac.

15. Should files and directories be the same
class.

Probably not. While they share a lot of common
functionality (which should be spelled out as an
interface) they also have a lot of dissimilar
functionality. Separating them also makes it easy
to create objects for things like symbolic links.

In addition to this, we should have the ability
to update the other times (utime()) directly
using another file or directory object as well
as a Datetime object.

John Roth



Relevant Pages

  • Re: PRE-PEP: new Path class
    ... >>subclass of single byte or unicode strings, ... string class it should subclass. ... >>particular file system has in it's warped little mind. ... If the path object describes a directory, ...
    (comp.lang.python)
  • Re: Creating a derived object from a base object
    ... I don't want to write a separate MyString ToUpper method when String ... subclass object thru a baseclass reference will use the *old* methods. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is there a Function and Function Argument generic self-reference?
    ... Private Class Common ... Public Overridable Function As String ... Sub Stored_Procedure_Common(ByVal Command As DB2Command) ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Userform to obtain folder (path) info ?
    ... You can modify the Common dialog control to open up as a browse folder ... ByVal lpBuffer As String) As Long ... Dim lpIDList As Long ...
    (microsoft.public.word.vba.userforms)
  • How display Windows dialog to get a file destination?
    ... documented how to call the Open common Dialog box. ... '* Created by Microsoft ... Public Function GetOpenFile(strInitialDir As String, ... Dim typWinOpen As API_WINOPENFILENAME ...
    (microsoft.public.access.formscoding)

Loading