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


Groups > comp.lang.python > #28877

Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.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 <mail@timgolden.me.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'paths': 0.05; 'api': 0.09; 'python': 0.09; 'does,': 0.09; 'sep': 0.09; 'subject:Lib': 0.09; 'bug': 0.10; 'cc:addr:python-list': 0.10; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 0.16; 'otherwise:': 0.16; 'prepend': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:os.py': 0.16; 'tjg': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'string,': 0.17; 'unicode': 0.17; '>>>': 0.18; 'import': 0.21; 'cc:2**0': 0.23; 'work.': 0.23; 'monday,': 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; 'supported': 0.26; 'in.': 0.27; 'to?': 0.27; 'subject:/': 0.28; '-0700,': 0.29; "d'aprano": 0.29; 'idea,': 0.29; 'steven': 0.29; 'workaround': 0.29; 'file': 0.32; 'print': 0.32; 'docs': 0.33; 'received:192.168.100': 0.33; 'but': 0.36; 'should': 0.36; 'does': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'skip:o 20': 0.38; 'received:192': 0.39; 'notice': 0.39; 'received:192.168': 0.40; 'leading': 0.61; 'first': 0.61; "you'll": 0.62; 'situation': 0.62; 'from:addr:mail': 0.71; 'sounds': 0.71; 'subject:get': 0.81; 'consequently': 0.84; 'officially': 0.91; 'to:none': 0.93
Date Tue, 11 Sep 2012 08:20:42 +0100
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0
MIME-Version 1.0
CC python-list@python.org
Subject Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py
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>
In-Reply-To <504eb3fc$0$29890$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
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>
Newsgroups comp.lang.python
Message-ID <mailman.489.1347348083.27098.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347348083 news.xs4all.nl 6884 [2001:888:2000:d::a6]:35974
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28877

Show key headers only | View raw


On 11/09/2012 04:46, Steven D'Aprano wrote:
> On Mon, 10 Sep 2012 15:22:05 -0700, ruck wrote:
> 
>> On Monday, September 10, 2012 1:16:13 PM UTC-7, Steven D'Aprano wrote:
> [...]
>>> That's not so much a workaround as the officially supported API for
>>> dealing with the situation you are in. Why don't you just prepend a 
>>> '?' to paths like they tell you to?
>>
>> Good idea, but the first thing os.walk() does is a listdir(), and
>> os.listdir() does not like the r'\\?\' prefix.  In other words,
>> os.walk(r'\\?\C:Users\john\Desktop\sandbox\goo') does not work.
> 
> Now that sounds like a bug to me. If Microsoft officially support 
> leading ? in file names, then so should Python on Windows.

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:

import os
os.listdir(u"\\\\?\\c:\\users")

# and consequently

for p, ds, fs in os.walk(u"\\\\?\\c:\\users"):
  print p


TJG

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


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