Not logged in
Log in now
Create an account
Subscribe to LWN
LWN.net Weekly Edition for May 16, 2013
A look at the PyPy 2.0 release
PostgreSQL 9.3 beta: Federated databases and more
LWN.net Weekly Edition for May 9, 2013
(Nearly) full tickless operation in 3.10
You didn't provide a link for the problem, but is this what you're looking for?
os.listdir(b'.') # no decoding for me, thanks
Moving to Python 3
Posted Feb 10, 2011 15:38 UTC (Thu) by nevyn (subscriber, #33129)
1. When calling listdir() directly, the default is broken (and in a non-obvious way) ... so everybody has to remember "Oh, yeh, you have to call os.listdir() in this speciail way or it's broken".
2. It assumes people are calling os.listdir() directly ... which is _far_ from the normal case. So now, to do the same hack, every API that eventually calls listdir() will have to implement/debug the bytes vs. unicode input vs. output thing ... and every caller of those APIs will have to remember "Oh, yeh, you have to call foo_API() in this speciail way or it's broken".
3. It's still not obvious what you _do_ with those bytes, because the reason listdir() doesn't work "normally" is that it's model of the Universe doesn't match reality. Basically you can't load a POSIX filename, and print "Error: open(%s): %s" ... and this problem is much bigger than POSIX filenames, it's just that's the most glaringly broken problem that people see. So the whole thing is a huge clue that "Unicode" is not any better in py-3 than it is in py-2 (which is to say, it's completely broken).
Posted Feb 12, 2011 0:13 UTC (Sat) by cmccabe (guest, #60281)
Python has a pretty long history of "forcing" what it believes to be the correct behavior on its users. It even tells you how to use whitespace. I am not surprised at all that they ignore non-UTF filenames. Frankly, it's a good decision.
Posted Feb 12, 2011 1:50 UTC (Sat) by foom (subscriber, #14868)
Posted Feb 15, 2011 1:24 UTC (Tue) by yuhong (guest, #57183)
Posted Feb 15, 2011 14:32 UTC (Tue) by nevyn (subscriber, #33129)
It is exactly python's fault that it pretends unix is like windows, when it isn't.
Posted Feb 15, 2011 14:52 UTC (Tue) by foom (subscriber, #14868)
Except that python doesn't actually do that, see comment above...
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds