[Python-Dev] Python-3.0, unicode, and os.environ

Toshio Kuratomi a.badger at gmail.com
Fri Dec 5 00:16:27 CET 2008


Adam Olsen wrote:
> On Thu, Dec 4, 2008 at 2:19 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Toshio Kuratomi wrote:
>>> The bug report I opened suggests creating a PEP to address this issue.
>>> I think that's a good idea for whether os.listdir() and friends should
>>> be changed to raise an exception but not having any way to get at some
>>> environment variables seems like it's just a bug that needs to be
>>> addressed.  What do other people think on both these issues?
>> I'm pretty sure the discussion on this topic a while back decided that
>> where necessary Python 3 would grow parallel bytes versions of APIs
>> affected by environmental encoding issues (such as os.environb,
>> os.listdirb, os.getcwdb), but that we were OK with the idea of deferring
>> addition of those APIs until 3.1.
> 
> It looks like most of them got into 3.0.
> http://docs.python.org/3.0/library/os.html says "All functions
> accepting path or file names accept both bytes and string objects, and
> result in an object of the same type, if a path or file name is
> returned."
> 
<nod>  I'm very glad this is coming along.  Just want to make sure the
environment is also handled in 3.1.
> 
>> That is, this was an acknowledged limitation with a fairly
>> straightforward agreed solution, but it wasn't considered a common
>> enough issue to delay the release of 3.0 until all of those parallel
>> APIs had been implemented
> 
> Aye.  IMO it's fairly clear that os.getenv()/os.putenv() should follow
> suit in 3.1.  I'm not so sure about adding os.environb (and making
> subprocess use it), unless the OP can demonstrate they really need it.
> 
Note: subprocess currently uses the "real" environment (the raw
environment as given to the python interpreter) when it is started
without the `env` parameter.  So the question would be what people
overriding the env parameter on their own need to do.

To be non-surprising I'd think they'd want to have a way to override
just a few variables from the raw environment.  Otherwise you have to
know which variables the program you're calling relies on and make sure
that those are set or call os.getenvb() to retrieve the byte version and
add it to your copy of os.environ before passing that to subprocess.

One example of something that would be even harder to implement without
access to the os.environb dictionary would be writing a program that
wraps make.  Since make takes all the variables from the environment and
transforms them into make variables you need to pass everything from the
environment that you are not modifying into the command.

-Toshio

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20081204/aceadea2/attachment-0001.pgp>


More information about the Python-Dev mailing list