Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28899
| 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 | <john.ruckstuhl@gmail.com> |
| 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 | <mailman.489.1347348083.27098.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=38.111.159.185; posting-account=iDie7AoAAAAFO32oTp1PonAhlnaPMExO |
| References | <a4a2e63b-d25d-4487-bff8-67d4b7c40cbc@googlegroups.com> <504e4a8d$0$29981$c3e8da3$5496439d@news.astraweb.com> <83af64e3-bc26-4217-8afa-e4f6d45b604d@googlegroups.com> <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com> <mailman.489.1347348083.27098.python-list@python.org> |
| 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 <john.ruckstuhl@gmail.com> |
| 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 <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> |
| Message-ID | <mailman.515.1347390828.27098.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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 just 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 "<pyshell#3>", line 1, in <module>
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 ntpath module, and I was really puzzled as to why it wasn't getting picked up! According to sys.path I expected my custom ntpath.py to be chosen, instead of the standard Lib/ntpath.py.
Now I guess I understand why. I moved Lib/ntpath.* out of the way, and learned that during initialization, Python is importing "site" module, which is importing "os" which is importing "ntpath" -- before my dir is added to sys.path. So later when I import os, it and ntpath have already been imported, 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-10 10:25 -0700
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-10 20:16 +0000
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-10 15:22 -0700
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-11 03:46 +0000
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Tim Golden <mail@timgolden.me.uk> - 2012-09-11 08:20 +0100
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-11 12:13 -0700
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Chris Angelico <rosuav@gmail.com> - 2012-09-12 08:50 +1000
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Dave Angel <d@davea.name> - 2012-09-11 18:57 -0400
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py ruck <john.ruckstuhl@gmail.com> - 2012-09-11 12:13 -0700
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-12 08:17 +0200
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py aahz@pythoncraft.com (Aahz) - 2012-11-09 16:42 -0800
csiph-web