Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7744

Re: os.path and Path

Date 2011-06-16 09:05 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: os.path and Path
References <mailman.8.1308188800.1164.python-list@python.org> <4df9ad53$0$29973$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.16.1308239495.1164.python-list@python.org> (permalink)

Show all headers | View raw


Steven D'Aprano wrote:
> On Wed, 15 Jun 2011 19:00:07 -0700, Ethan Furman wrote:
> 
>> Thread 1: "objects of different types compare unequal" self:    
>> "nonsense!  we have the power to say what happens in __eq__!"
>>
>> Thread 2: "objects that __hash__ the same *must* compare __eq__!" self: 
>>    "um, what? ... wait, only immutable objects hash..."
> 
> Incorrect. 
> What you mean to say is that if objects compare equal, they must hash the 
> same. Not the other way around.

Ack.  I keep saying that backwards.  Thanks for the correction.


>> Thread 2: "you're Path object is immutable..." self:     "argh!"
>>
>> Here's the rub:  I'm on Windows (yes, pity me...) but I prefer the
>> unices, so I'd like to have / seperate my paths.  But I'm on Windows...
> 
> Any sensible Path object should accept path components in a form 
> independent of the path separator, and only care about the separator when 
> converting to and from strings.

Our ideas of 'sensible' apparently differ.

One of my goals with my Path objects was to be a drop-in replacement for 
the strings currently used as paths; consequently, they are a sub-class 
of string, and can still be passed to, for example, os.path.splitext(). 
  Another was to be able to use '/' across all platforms, but still have 
the appropriate separator used when the Path object was passed to, for 
example, open().

To me, a path is an ambiguous item:  /temp/here/xyz.abc
where does the directory structure stop and the filename begin?  xyz.abc 
could be either the last subdirectory, or the filename, and the only way 
to know for sure is to look at the disk.  However, the Path may not be 
complete yet, or the final item may not exist yet -- so what then?  I'm 
refusing the temptation to guess. ;)  The programmer can explicity look, 
or create, appropriately.


> [...] 
>> So, I suppose I shall have to let go of my dreams of
>>
>> --> Path('/some/path/and/file') == '\\some\\path\\and\\file'
> 
> To say nothing of:
> 
> Path('a/b/c/../d') == './a/b/d'

I think I'll make my case-insensitive Paths compare, and hash, as 
all-lowercase, so direct string comparison can still work.  I'll add an 
.eq() method to handle the other fun stuff.


> Why do you think there's no Path object in the standard library? *wink*

Because I can't find one in either 2.7 nor 3.2, and every reference I've 
found has indicated that the other Path contenders were too 
all-encompassing.

~Ethan~

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-15 19:00 -0700
  Re: os.path and Path Laurent Claessens <moky.math@gmail.com> - 2011-06-16 09:03 +0200
    Re: os.path and Path Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-16 07:58 +0000
      Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 09:16 -0700
        Re: os.path and Path Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-16 16:41 +0000
          Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 10:18 -0700
          Re: os.path and Path Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-16 11:21 -0600
      Re: os.path and Path Christian Heimes <lists@cheimes.de> - 2011-06-16 18:32 +0200
      Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 10:07 -0700
      Re: os.path and Path Chris Angelico <rosuav@gmail.com> - 2011-06-17 11:00 +1000
  Re: os.path and Path Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-16 07:14 +0000
    Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 09:05 -0700
      Re: os.path and Path Chris Torek <nospam@torek.net> - 2011-06-17 00:48 +0000
        Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 18:19 -0700
        Re: os.path and Path Ned Deily <nad@acm.org> - 2011-06-16 19:55 -0700
          Re: os.path and Path rusi <rustompmody@gmail.com> - 2011-06-16 21:24 -0700

csiph-web