At 08:24 PM 6/27/2005 +0100, Michael Hoffman wrote:
>On Mon, 27 Jun 2005, Phillip J. Eby wrote:
>
> > At 08:20 AM 6/27/2005 +0100, Michael Hoffman wrote:
> >> os.getcwd() returns a string, but path.getcwd() returns a new path
> >> object.
> >
> > In that case, I'd expect it to be 'path.fromcwd()' or 'path.cwd()'; i.e. a
> > constructor classmethod by analogy with 'dict.fromkeys()' or
> > 'datetime.now()'.  'getcwd()' looks like it's getting a property of a path
> > instance, and doesn't match stdlib conventions for constructors.
> >
> > So, +1 as long as it's called cwd() or something better (i.e. clearer
> > and/or more consistent with stdlib constructor conventions).
>
>+1 on cwd().
>
>-1 on making this the default constructor. Essentially the default
>constructor returns a path object that will reflect the CWD at the
>time that further instance methods are called.

Only if we make the default argument to path() be os.curdir, which isn't a 
bad idea.


>Unfortunately only some of the methods work on paths created with the
>default constructor:
>
> >>> path().listdir()
>Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
>    File "/usr/lib/python2.4/site-packages/path.py", line 297, in listdir
>      names = os.listdir(self)
>OSError: [Errno 2] No such file or directory: ''

This wouldn't be a problem if the default constructor arg were os.curdir 
(i.e. '.' for most platforms) instead of an empty string.


>Is there support to have all of the methods work when the path is the
>empty string? Among other benefits, this would mean that sys.path
>could be turned into useful path objects with a simple list
>comprehension.

Ugh.  sys.path entries are not path objects, nor should they be.  PEP 302 
(implemented in Python 2.3 and up) allows sys.path to contain any strings 
you like, as interpreted by objects in sys.path_hooks.  Programs that 
assume only filesystem paths appear in sys.path will break in the presence 
of PEP 302-sanctioned import hooks.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to