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


Groups > comp.lang.python > #80011

Re: set environmental variable from python

Path csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.87.MISMATCH!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.020
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'python.': 0.02; '(at': 0.04; 'made.': 0.07; 'users,': 0.07; 'variables': 0.07; 'restart': 0.09; 'subject:set': 0.09; 'variables.': 0.09; 'windows,': 0.09; 'python': 0.11; '2.7': 0.14; 'itself.': 0.14; 'changes': 0.15; 'windows': 0.15; 'cmd': 0.16; 'does,': 0.16; 'have)': 0.16; 'indirectly': 0.16; 'mean,': 0.16; 'subject:skip:e 10': 0.16; 'subject:variable': 0.16; 'survive': 0.16; 'variants': 0.16; 'win7': 0.16; 'subject:python': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'items.': 0.19; 'user.': 0.19; 'machine': 0.22; '>>>': 0.22; 'rules': 0.22; 'shell': 0.22; 'header:User- Agent:1': 0.23; '31,': 0.24; '(or': 0.24; 'environment': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'thus': 0.29; 'dos': 0.30; 'sets': 0.30; 'easier': 0.31; 'page.': 0.31; 'once,': 0.31; 'values.': 0.31; 'there.': 0.32; 'run': 0.32; 'another': 0.32; 'quite': 0.32; 'fri,': 0.33; 'subject:from': 0.34; 'could': 0.34; 'but': 0.35; 'google': 0.35; 'there': 0.35; 'controls': 0.36; 'module.': 0.36; 'useful': 0.36; 'thanks': 0.36; 'url:microsoft': 0.37; 'two': 0.37; 'remote': 0.38; 'system,': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'launch': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'dave': 0.60; 'manually': 0.60; 'affect': 0.61; 'new': 0.61; 'first': 0.61; "you'll": 0.62; 'advanced': 0.63; 'term': 0.63; 'such': 0.63; 'different': 0.65; 'dear': 0.65; '30,': 0.65; 'here': 0.66; 'answer.': 0.68; 'panel': 0.68; 'received:74.208': 0.68; 'url:en-us': 0.68; 'user,': 0.69; 'yourself': 0.78; 'future,': 0.83; '2014,': 0.84; 'boxes.': 0.84; 'links:': 0.84; 'panel:': 0.84; 'permanently.': 0.84; 'played': 0.84; 'received:74.208.4.194': 0.84; 'safer': 0.84; 'started,': 0.84; 'angel': 0.91; 'ware': 0.91; 'children.': 0.93
Date Fri, 31 Oct 2014 08:34:08 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: set environmental variable from python
References <CA+F4vi=3g_y-N7qrAyuTArj5kKXVzXhe8W+tfWQVcA2OjGUfpQ@mail.gmail.com> <5452EAE2.8020500@davea.name> <CA+F4vi=vXj4Ge+_69YwiNpn11gbSBmdgyouC2Z5wUpWxKPxuYQ@mail.gmail.com> <CAKJDb-PK-WXDr8KBHk0adB7QNG844G-GyOpYWip=BgAkb37rAQ@mail.gmail.com> <CA+F4vi=cfS_QhXtDx_+3jmWDdTrnx=bPk_84hzFaib4QQEZ7Sg@mail.gmail.com>
In-Reply-To <CA+F4vi=cfS_QhXtDx_+3jmWDdTrnx=bPk_84hzFaib4QQEZ7Sg@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:JjKG03UwnqB+EvILGOmahY4yqZklQfRp9jCwN+gKJKc jZkB63gZGC9rmE2j89RdzZnP+SOlQAGQ32/QZV3Q5jOCEb3Xb2 gYpOjVxoa3vVIM1cLjNstAOd7aeZrKYrPMZNCkvzGy7yau9uUd iMoPoi1ueyVlh2HSinKInWu/qvdOyja1VS3nSgIMdBLOlXUb+M IlvXtQtCF5jWBS+Wgb2ykq7hstsSQZ2w+xgVMtJe2ZtoGZDSLJ rF8GUILCOVgZwc1ChLWV4C5ChMBgIifptUJ4nKdC2z3nmmCcbk uwkn1/GWTmxZu433tA1uxRwPBeS2nQH/sGwzv+ktyZHF8I65zR gmeKkAZvqyEXqFHwrvBk=
X-UI-Out-Filterresults notjunk:1;
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15353.1414758854.18130.python-list@python.org> (permalink)
Lines 82
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414758854 news.xs4all.nl 2933 [2001:888:2000:d::a6]:58568
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80011

Show key headers only | View raw


On 10/30/2014 10:40 PM, Artur Bercik wrote:

> On Fri, Oct 31, 2014 at 11:30 AM, Zachary Ware <
> zachary.ware+pylist@gmail.com> wrote:
>
>> On Thursday, October 30, 2014, Artur Bercik <vbubbly21@gmail.com> wrote:
>>
>>> Dear Dave Angel
>>>
>>> Thanks for your answer.
>>>
>>> I am using Python 2.7
>>>
>>> I want to set it permanently.
>>> I have to set several variables so it would be easier if I could set them
>>> from Python.
>>>
>>
>> Depending on how "permanently" you mean, about your only solutions would
>> be "os.system('setx <...>')" or manually manipulating the registry with the
>> _winreg module.
>>
>
>
 > could you please elaborate 'setx <...>'?
 >

SETX is a Windows utility.  I don't run Windows, but I found a Win7 
machine and played again.  I used to be quite knowledgeable about 
Windows, but I could get parts of the following wrong.

To see what SETX does, type (at a cmd line):

SETX /?

Or google it.  (I used duckduckgo, and here are the first two useful 
links:  Obviously the second one is an official Microsoft page.

http://ss64.com/nt/setx.html
http://technet.microsoft.com/en-us/library/cc755104.aspx

There are several variants of "permanent" that are relevant here.

1) Nothing you change in one process will change another process that's 
already running.  That includes any shells you might have already 
started, such as DOS boxes.  (cmd windows)  And the term shell here also 
includes any other already-running process that is going to launch 
another program.  The shell controls its child's environment, and in 
general do not check the registry for changes you might have made.

2) SETX will affect new processes launched directly from Windows (eg. 
from Explorer), because it changes the registry itself.

3) SETX will affect *new* shells launched, and thus indirectly affect 
their children.

4) SETX effects will survive a reboot.  So when you restart your system, 
you'll still see the new values.  Incidentally, that's the first time 
when you'll be sure that all processes will see the new values.

5) SETX can be used on remote (networked) systems, and the rules are 
somewhat different there.

6) If you have (or ever will have) multiple users, you have to consider 
whether you want to affect the system environment variables or just one 
user.  And if just one user, whether it's yourself or some other 
account, such as Administrator.  Every time a process is launched by the 
system, it builds an environment from TWO sets of registry items.  So if 
you want to affect all users, you need to change the system variables.


If you are just going to do this once, and you want to affect all the 
processes that ever run in the future, you'll be much safer using the 
control panel:

Control Panel | System | Advanced | Environment Variables




-- 
DaveA

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


Thread

Re: set environmental variable from python Dave Angel <davea@davea.name> - 2014-10-31 08:34 -0400

csiph-web