Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'sys': 0.07; 'variables': 0.07; 'name?': 0.09; 'subject:set': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'assume': 0.14; '2.7': 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; 'solution.': 0.20; 'code,': 0.22; 'import': 0.22; 'python?': 0.22; 'cc:addr:python.org': 0.22; '31,': 0.24; 'environment': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'easier': 0.31; '3.x': 0.31; 'another': 0.32; 'url:python': 0.33; 'fri,': 0.33; 'at:': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'could': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'next': 0.36; 'method': 0.36; 'thanks': 0.36; "i'll": 0.36; 'possible': 0.36; 'url:org': 0.36; 'follows:': 0.38; 'url:library': 0.38; 'planning': 0.38; 'pm,': 0.38; 'realize': 0.39; 'url:mail': 0.40; 'how': 0.40; 'dave': 0.60; 'hope': 0.61; 'url:3': 0.61; 'name:': 0.61; "you're": 0.61; 'hearing': 0.63; 'name': 0.63; 'such': 0.63; 'dear': 0.65; 'believe': 0.68; 'answer.': 0.68; 'saving': 0.69; 'permanently.': 0.84; 'angel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=TCmHp9bv6bzr6o3sBSZ0KN2lMkiZJcYGiXDp1lT/lNQ=; b=DaGevDwppw06imgSvfqnOW0MXHwwURWzinUCRpXj4kxkgVy/FmZ+igpZK07GwolxgW JPUWVGoFj/6BhgrYBEPX6cQq1pL+DEqNY3Ygm4F5x0KIIwluVTzU08mPgHW7uwbHd6aa TUxbzpNdpOVK+MigvxVUJDbUid58f8tza7W4+zffd3vha5ES/UGg8RdcTlhesLIDMO1R VdZI3MoZJqMYcsZsvwSogm212Mrjp1SChnvKPV/0147ORae8Mxse+DbM1DkV3J37+dM+ uen3JtZ49iJtCIrtPCr3pUEP8kkNHShMTgvHWoQ6efOTfg4SN5eZAq7KR6z7O10bxnfE FVqQ== X-Received: by 10.60.82.163 with SMTP id j3mr17565863oey.13.1414721001276; Thu, 30 Oct 2014 19:03:21 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <5452EAE2.8020500@davea.name> References: <5452EAE2.8020500@davea.name> From: Artur Bercik Date: Fri, 31 Oct 2014 11:03:01 +0900 Subject: Re: set environmental variable from python To: Dave Angel Content-Type: multipart/alternative; boundary=047d7b5dbcfabccc0a0506ae6688 Cc: "python-list@python.org" 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: 135 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414721010 news.xs4all.nl 2952 [2001:888:2000:d::a6]:57836 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79989 --047d7b5dbcfabccc0a0506ae6688 Content-Type: text/plain; charset=UTF-8 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. Hearing the solution. On Fri, Oct 31, 2014 at 10:50 AM, Dave Angel wrote: > 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 > -- > https://mail.python.org/mailman/listinfo/python-list > --047d7b5dbcfabccc0a0506ae6688 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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.

= Hearing the solution.

On Fri, Oct 31, 2014 at 10:50 AM, Dave Angel <davea@davea.= name> wrote:
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?=C2=A0 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:

=C2=A0 =C2=A0 =C2=A0 https://docs.python.org/3/library/os.html

Also see os.getenv and os.setenv.



Note that it's not necessarily supported.=C2=A0 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 d= o realize that it will vanish again when your python process ends?=C2=A0 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 Py= thon code.

--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list

--047d7b5dbcfabccc0a0506ae6688--