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: 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 User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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. :( ~Ethan~ What, you didn't see the opening 'whine' tag? Oh, well, my xml isn't very good... ;)