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


Groups > comp.lang.python > #48652

Re: os.putenv() has no effect

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'assign': 0.07; 'environments': 0.07; 'linux,': 0.07; 'modify': 0.07; '"if': 0.09; 'function,': 0.09; 'preferable': 0.09; 'things,': 0.09; 'python': 0.11; 'bug': 0.12; 'os.environ': 0.16; 'subject:effect': 0.16; 'sure.': 0.16; 'why,': 0.16; 'wrote:': 0.18; 'header:User- Agent:1': 0.23; "shouldn't": 0.24; "i've": 0.25; 'header:In-Reply- To:1': 0.27; 'appreciated.': 0.29; "doesn't": 0.30; "i'm": 0.30; '>>>>': 0.31; 'ordinary': 0.31; 'could': 0.34; 'anybody': 0.35; 'but': 0.35; 'words,': 0.36; 'doing': 0.36; 'should': 0.36; 'application': 0.37; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'environment.': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'group,': 0.63; 'happen': 0.63; 'received:74.208': 0.68; 'obvious': 0.74; 'dict,': 0.84; 'received:74.208.4.194': 0.84
Date Tue, 18 Jun 2013 14:09:11 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6
MIME-Version 1.0
To python-list@python.org
Subject Re: os.putenv() has no effect
References <kpq32r$cdc$1@news.albasani.net>
In-Reply-To <kpq32r$cdc$1@news.albasani.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:fmRBY2b8FUvlarIJxxLfd7feFi3+Jubxpe524b60sq0 ynvkcDqPKtguhN+ksMxFrETBlF5JeAYl1ibV3CZuVn74zjCkAG zlHpDscyHX98x4M4k7IAxpwPNXi/1slTXXkb6rkHOs3xPR9IQ7 ah1mS1eb7TYIOcK20Zhm5zaUbt1baCgUmhESB3qo5Uv3mKIOr0 HaTeF4n1lYtQOp7xvuTVgBVhzWycG5nDfh7XW2bPZt0XrwX4iV VqGMqYCBU49F6hPE3oQOm4/fdKS5VQ7Px/35KIFU3VqEFccINM oRXhDJiPbr1bhEYj9K1prh6j6+jnC3NtwG79io22h4uWeonD5N bqNKAsJfBvlT00lBG4hU=
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.3552.1371578965.3114.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371578965 news.xs4all.nl 15906 [2001:888:2000:d::a6]:57679
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48652

Show key headers only | View raw


On 06/18/2013 12:49 PM, Johannes Bauer wrote:
> Hi group,
>
> I've tracked down a bug in my application to a rather strange
> phaenomenon: os.putenv() doesn't seem to have any effect on my platform
> (x86-64 Gentoo Linux, Python 3.2.3):
>
>>>> os.getenv("PATH")
> '/usr/joebin:/usr/local/bin:/usr/bin:/bin:/usr/games/bin:/usr/sbin:/sbin:~/bin'
>>>> os.putenv("PATH", "/")
>>>> os.getenv("PATH")
> '/usr/joebin:/usr/local/bin:/usr/bin:/bin:/usr/games/bin:/usr/sbin:/sbin:~/bin'
>
>
>>>> os.getenv("FOO")
>>>> os.putenv("FOO", "BAR")
>>>> os.getenv("FOO")
>>>>
>
> Does anybody know why this would happen or what I could be doing wrong?
> Help is greatly appreciated.
>

Quoting (retyping) from the getenv docs, "...however, calls to putenv() 
don't update os.environ, so it is actually preferable to assign to items 
of os.environ."

As to why, I'm not at all sure.  Only that many environments don't 
support putenv().  But why that should stop it working in the obvious 
way ?  No idea.

os.environ is not an ordinary dict, it's a "mapping object".  And among 
other things, when you modify os.environ, Python will call putenv. 
Quoting from the os.environ docs, "If the platform supports the putenv() 
function, this mapping may be used to modify the environment.  putenv() 
will be called automatically wehn the mapping is modified."

In other words, you shouldn't use putenv(), but instead modify os.environ.

-- 
DaveA

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


Thread

os.putenv() has no effect Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-18 18:49 +0200
  Re: os.putenv() has no effect Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-18 19:48 +0200
  Re: os.putenv() has no effect inq1ltd <inq1ltd@inqvista.com> - 2013-06-18 13:24 -0400
  Re: os.putenv() has no effect Dave Angel <davea@davea.name> - 2013-06-18 14:09 -0400
    Re: os.putenv() has no effect Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-18 20:12 +0200
      Re: os.putenv() has no effect Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-18 20:16 +0200
  Re: os.putenv() has no effect Skip Montanaro <skip@pobox.com> - 2013-06-18 13:22 -0500
  Re: os.putenv() has no effect Terry Reedy <tjreedy@udel.edu> - 2013-06-18 16:31 -0400

csiph-web