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

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Sep 10 23:46:04 EDT 2012


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.


> Also, your recipe worked for me --
> I'm walking 'goo' which contains 'voo.../doo'

Good for you. (Sorry, that comes across as more condescending than it is 
intended as.) Monkey-patching often gets used for quick scripts and tiny 
pieces of code because it works.

Just beware that if you extend that technique to larger bodies of code, 
say when using a large framework, or multiple libraries, your experience 
may not be quite so good. Especially if *they* are monkey-patching too, 
as some very large frameworks sometimes do. (Or so I am lead to believe.)

The point is not that monkey-patching is dangerous and should never be 
used, but that it is risky and should be used with caution.



-- 
Steven



More information about the Python-list mailing list