Environment Variable

T

tuxlover

Is it possible to set an environment variable from inside the python
script which will be retained after the script exits.

If I use the following code:

import os
os.putvar("name", "tuxlover")

the enivironment variable name is visible to only the sub-process
created by os.system and os.popen. But as soon as the python script
vanishes, the environment variable "name" is gone.

What I am wondering is that is it possible to set a environment
variable from inside a python script, and then access it (say, echo
$name from the shell) after the python script exits.

Thanks
Tuxlover
 
R

Reinhold Birkenfeld

Is it possible to set an environment variable from inside the python
script which will be retained after the script exits.

If I use the following code:

import os
os.putvar("name", "tuxlover")

the enivironment variable name is visible to only the sub-process
created by os.system and os.popen. But as soon as the python script
vanishes, the environment variable "name" is gone.

What I am wondering is that is it possible to set a environment
variable from inside a python script, and then access it (say, echo
$name from the shell) after the python script exits.

No, I regret it is currently not. But I see a significant chance that
someone gets on the time machine and implants this into Thompson's head
some 30 years earlier as soon as you post that a third time.

Reinhold
 
P

Peter Hansen

Is it possible to set an environment variable from inside the python
script which will be retained after the script exits.

Since it appears you are reposting the same question that started this
thread: were Grant's and Sybren's replies unsatisfactory and, if so, in
what way?

-Peter
 
T

tuxlover

No, the replies from Grant's and Sybren's do answer my question. I
posted twice because my browser locked itself up, and I ended up typing
twice :(
 
S

Sybren Stuvel

tuxlover enlightened us with:
No, the replies from Grant's and Sybren's do answer my question.

It would be a lot more polite to actually thank the people helping
you.

Sybren
 
C

Cameron Laird

tuxlover enlightened us with:

It would be a lot more polite to actually thank the people helping
you.
.
.
.
Expressing gratitude is indeed a courtesy.

As an old-time Usenetter, I also have a high regard for
economy or brevity; I generally communicate my thanks in
private e-mail, unless I can embed them in a comment which
I think is likely to interest a wider audience. I have in
mind something on the order of, "Thanks, timbot! I notice
that not only does that solution conform to IEEE 754, as
requested, but it's compatible with the Rayleigh-Ritz
implementation found in ..."

I'm certain neither of Mr. Stuvel's point, nor of whether
it applied to tuxlover's actual behavior. I wouldn't want
readers to think, though, that every well-formed clp thread
must necessarily terminate in a follow-up whose content is
limited to "Thx."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top