[Python-Dev] Patch for an initial support of bytes filename in Python3

Guido van Rossum guido at python.org
Wed Oct 1 00:04:03 CEST 2008


On Tue, Sep 30, 2008 at 11:47 AM,  <glyph at divmod.com> wrote:
>
> On 05:56 pm, guido at python.org wrote:
>>
>> On Tue, Sep 30, 2008 at 10:59 AM,  <glyph at divmod.com> wrote:
>>>
>>> On 02:32 pm, guido at python.org wrote:
>
>>> In the absence of a 2.6 getcwdb, perhaps the fixer could just drop the
>>> "benefit of the doubt" case?  It could always be added to 2.7, and the
>>> parity release of 2to3 could have a --2.7 switch that would modify the
>>> behavior of this and other fixers.
>>
>> I'm not sure what you're proposing. *My* proposal is that 2to3 changes
>> os.getcwdu() calls to os.getcwd() and leaves os.getcwd() calls alone
>> -- there's no way to tell whether os.getcwdb() would be a better
>> match, and for portable code, it won't be (since os.getcwdb() is a
>> Unix-only thing).
>
> My proposal is simply to change getcwd to getcwdb, and getcwdu to getcwd.
>  This preserves whatever bytes/text behavior you are expecting from 2.6 into
> 3.0.  Granted, the fact that unicode is really always the right thing to do
> on Windows complicates things.

Plus, even on Linux Unicode is *usually* what you should be doing,
unless you're writing a backup tool.

> I already tend to avoid os.getcwd() though, and this is just one more reason
> to avoid it.  In the rare cases where I really do need it, it looks like
> os.path.abspath(b".") / os.path.abspath(u".") will provide the clarity that
> I want.

Or os.path.expanduser('~') vs. os.path.expanduser(b'~'). :-)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list