Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'sys': 0.07; 'name?': 0.09; 'subject:set': 0.09; 'python': 0.11; 'assume': 0.14; 'windows': 0.15; 'os.environ': 0.16; 'subject:skip:e 10': 0.16; 'subject:variable': 0.16; 'supported.': 0.16; 'sys.path': 0.16; 'variable.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'value.': 0.19; 'code,': 0.22; 'import': 0.22; 'python?': 0.22; 'header:User-Agent:1': 0.23; 'environment': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; '3.x': 0.31; 'another': 0.32; 'url:python': 0.33; 'at:': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'could': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'next': 0.36; 'method': 0.36; "i'll": 0.36; 'possible': 0.36; 'url:org': 0.36; 'follows:': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'planning': 0.38; 'pm,': 0.38; 'realize': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'hope': 0.61; 'url:3': 0.61; 'name:': 0.61; "you're": 0.61; 'name': 0.63; 'such': 0.63; 'believe': 0.68; 'received:74.208': 0.68; 'saving': 0.69; 'received:74.208.4.194': 0.84 Date: Thu, 30 Oct 2014 21:50:26 -0400 From: Dave Angel 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: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:KY0xUSnJK+utq9+bi4HTsOcieMyNBasFuQzP5PWuOTD GIwrDgvxPYR+4BlhQT4/T6eCwnvnR2Mz+WXPe/wcdVEk19WKs8 IE82kNDZcd96RuabDXY3dfVy2lj+Z/I+Dysrz6J7P6i3rU35BD dLtdslSQKl6EqbfLsNm0G1f6fIQKEOB8ucAsRTndtnwi/XrFpx DNLJRH0u611Irgxho5ZXJN90NNK5iS8r5mPKleoy5fn36nm1hW jAVM2XH0aS1ynNPOMxGKNKquSi5v05ndj98s+IymJR/dlzQVzd 3hpDmuIYUui1jBZ5LndeBUCOwz0b9buq1fBf4CAP6Znmb8fLXL T7n1ATiJJq3VvW1zTo+4= 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414720237 news.xs4all.nl 2921 [2001:888:2000:d::a6]:48480 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79990 On 10/30/2014 09:22 PM, Artur Bercik wrote: > I have to set environmental variable in my windows PC as follows: > > variable name: GISBASE > > value: C:\GRASS-64 > > Is it possible to set it from python? Which Python? I'll have to assume 3.x > > import sys > > sys.path.append("C:\\GRASS-64") > > But how to give variable name? I have to set both the variable name and > value. > sys.path has nothing to do with an environment variable of GISBASE. Instead you could look up os.environ at: https://docs.python.org/3/library/os.html Also see os.getenv and os.setenv. Note that it's not necessarily supported. But I believe it is for a standard build on Windows. Next question is what you hope to achieve by setting such a variable. You do realize that it will vanish again when your python process ends? So if you're just planning to use it in your own code, I'd recommend finding another method of saving the name & value. The only value I can see is if you plan to create a subprocess from your Python code. -- DaveA