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


Groups > comp.lang.python > #7719

os.path and Path

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'suppose': 0.05; 'behavior,': 0.07; 'forth.': 0.07; 'python': 0.08; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'oh,': 0.09; 'received:gator410.hostgator.com': 0.09; 'shortcut': 0.09; '~ethan~': 0.09; '*must*': 0.16; 'containers': 0.16; 'immutable': 0.16; 'paths.': 0.16; 'pity': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'seperate': 0.16; 'settle': 0.16; 'what?': 0.16; 'continuing': 0.17; 'primarily': 0.22; 'conversions': 0.23; 'objects': 0.23; 'code': 0.24; '(and': 0.25; 'compare': 0.26; 'xml': 0.26; 'windows': 0.26; 'object': 0.26; "i'm": 0.27; 'skip:p 30': 0.28; 'etc.,': 0.30; 'relying': 0.30; 'threads': 0.30; 'it.': 0.31; "didn't": 0.31; 'to:addr:python-list': 0.33; "isn't": 0.33; '...': 0.34; "i'll": 0.34; 'file': 0.34; 'header:User-Agent:1': 0.35; 'couple': 0.35; 'skip:r 30': 0.37; 'thread': 0.37; 'could': 0.38; 'but': 0.38; 'some': 0.38; "i'd": 0.39; 'to:addr:python.org': 0.39; 'power': 0.61; 'friendly': 0.63; 'back': 0.63; 'received:websitewelcome.com': 0.67; 'what,': 0.67; 'dreams': 0.84; 'self:': 0.84; 'wait,': 0.91
Date Wed, 15 Jun 2011 19:00:07 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To Python <python-list@python.org>
Subject os.path and Path
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:4206
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8.1308188800.1164.python-list@python.org> (permalink)
Lines 57
NNTP-Posting-Host 82.94.164.166
X-Trace 1308188801 news.xs4all.nl 49041 [::ffff:82.94.164.166]:54523
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7719

Show key headers only | View raw


In my continuing quest for Python Mastery (and because I felt like it ;) 
I decided to code a Path object so I could dispense with all the 
os.path.join and os.path.split and os.path.splitext, etc., etc., and so 
forth.

While so endeavoring a couple threads came back and had a friendly 
little chat in my head:

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..."

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...

So I thought, "Hey!  I'll just do some conversions in __eq__ and life 
will be great!"

--> some_path = Path('/source/python/some_project')
--> some_path == '/source/python/some_project'
True
--> some_path == r'\source\python\some_project'
True
--> # if on a Mac
--> some_path == ':source:python:some_project'
True
--> # oh, and because I'm on Windows with case-insensitive file names...
--> some_path == '/source/Python/some_PROJECT'
True

And then, of course, the ghosts of threads past came and visited.  For 
those that don't know, the __hash__ must be the same if __eq__ is the 
same because __hash__ is primarily a shortcut for __eq__ -- this is 
important when you have containers that are relying on this behavior, 
such as set() and dict().

So, I suppose I shall have to let go of my dreams of

--> Path('/some/path/and/file') == '\\some\\path\\and\\file'

and settle for

--> Path('...') == Path('...')

but I don't have to like it.  :(

</whine>

~Ethan~

What, you didn't see the opening 'whine' tag?  Oh, well, my xml isn't 
very good... ;)

Back to comp.lang.python | Previous | NextNext 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