Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79990
| Date | 2014-10-30 21:50 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: set environmental variable from python |
| References | <CA+F4vi=3g_y-N7qrAyuTArj5kKXVzXhe8W+tfWQVcA2OjGUfpQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15340.1414720237.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: set environmental variable from python Dave Angel <davea@davea.name> - 2014-10-30 21:50 -0400
csiph-web