Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!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; 'syntax': 0.03; 'importing': 0.04; 'diff': 0.05; 'paths': 0.05; 'override': 0.07; 'root,': 0.07; 'skip:o 50': 0.07; 'python': 0.09; 'does,': 0.09; 'filename,': 0.09; 'skip:o 60': 0.09; 'subject:Lib': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '*i*': 0.16; 'bad:': 0.16; 'corrects': 0.16; 'dirs,': 0.16; 'otherwise:': 0.16; 'prepend': 0.16; 'subject:os.py': 0.16; 'sys.path': 0.16; 'unicode.': 0.16; 'later': 0.16; 'wrote:': 0.17; 'module,': 0.17; 'string,': 0.17; 'unicode': 0.17; 'why.': 0.17; 'saying': 0.18; 'tim': 0.18; '>>>': 0.18; 'are:': 0.20; 'trying': 0.21; 'import': 0.21; '"",': 0.22; 'os,': 0.22; 'help.': 0.22; 'posted': 0.22; 'work,': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '---': 0.26; '(most': 0.27; 'guess': 0.27; 'label': 0.27; "doesn't": 0.28; 'subject:/': 0.28; "skip:' 50": 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'file': 0.32; 'suggestion': 0.32; 'could': 0.32; 'print': 0.32; 'getting': 0.33; '11,': 0.33; 'docs': 0.33; 'like:': 0.33; 'traceback': 0.33; 'up!': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'dir': 0.35; 'fresh': 0.35; 'moved': 0.35; 'expected': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; "wasn't": 0.36; "didn't": 0.36; 'does': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'object': 0.38; 'sure': 0.38; 'instead': 0.39; 'notice': 0.39; 'where': 0.40; 'john': 0.60; "you'll": 0.62; 'customized': 0.64; 'taking': 0.65; 'learned': 0.65; 'subject:get': 0.81; '[error': 0.84; 'confusion.': 0.84; 'good:': 0.84; 'teach.': 0.84 Newsgroups: comp.lang.python Date: Tue, 11 Sep 2012 12:13:45 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=38.111.159.185; posting-account=iDie7AoAAAAFO32oTp1PonAhlnaPMExO References: <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 38.111.159.185 MIME-Version: 1.0 Subject: Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py From: ruck To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347390828 news.xs4all.nl 6849 [2001:888:2000:d::a6]:41956 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28899 On Tuesday, September 11, 2012 12:21:24 AM UTC-7, Tim Golden wrote: > And so it does, but you'll notice from the MSDN docs that the \\? > syntax must be supplied as a Unicode string, which os.listdir > will do if you pass it a Python unicode object and not otherwise: I was saying os.listdir doesn't like the r'\\?\' prefix. But Tim corrects me -- so yes, Steven's earler suggestion "Why don't you ju= st prepend a '?' to paths like they tell you to?" does work, when I supply = it in unicode. Good: >>> os.listdir(u'\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') [u'voo...'] Bad: >>> os.listdir('\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') Traceback (most recent call last): File "", line 1, in os.listdir('\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo') WindowsError: [Error 123] The filename, directory name, or volume label= syntax is incorrect: '\\\\?\\C:\\Users\\john\\Desktop\\sandbox\\goo/*.*' Thanks to both of you for taking the time to teach. BTW, when I posted the original, I was trying to supply my own customized n= tpath module, and I was really puzzled as to why it wasn't getting picked u= p! According to sys.path I expected my custom ntpath.py to be chosen, inste= ad of the standard Lib/ntpath.py. Now I guess I understand why. I moved Lib/ntpath.* out of the way, and lea= rned that during initialization, Python is importing "site" module, which i= s importing "os" which is importing "ntpath" -- before my dir is added to s= ys.path. So later when I import os, it and ntpath have already been import= ed, so Python doesn't attempt a fresh import. To get my custom ntpath.py honored, need to RELOAD, like: import os import ntpath reload(ntpath) print 'os.walk(\'goo\') with isdir override in custom ntpath' for root, dirs, files in os.walk('goo'): print root, dirs, files where the diff betw standard ntpath.py and my ntpath.py are: 14c14,19 < from genericpath import * --- > from genericpath import * > > def isdir(s): > return genericpath.isdir('\\\\?\\' + abspath(s + '\\')) > def isfile(s): > return genericpath.isfile('\\\\?\\' + abspath(s + '\\')) I'm not sure how I could have known that ntpath was already imported, since= *I* didn't import it, but that was the key to my confusion. Thanks again for the help. John