473,503 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Environment Variable

Is it possible to set an environment variable in python script whose
value is retained even after the script exits.

Doing the following creates an environment variable "name" which is
visible to only subprocesses created by os.system() and os.popen().

os.putvar("name", "vivek")

Is it possible to somehow create this environment variable inside
python script which will be avaibale even after the script exits. In
otherwords, after I run my script, if I do a "echo $name" in my shell,
it should return the value "vivek"
Jul 21 '05 #1
4 2203
On 2005-07-11, Vivek Chaudhary <vi*******@yahoo.com> wrote:
Is it possible to set an environment variable in python script whose
value is retained even after the script exits.


No, not in Unix/Linux. In VMS I think there is.

--
Grant Edwards grante Yow! I think my CAREER
at is RUINED!!
visi.com
Jul 21 '05 #2
Vivek Chaudhary enlightened us with:
Is it possible to set an environment variable in python script whose
value is retained even after the script exits.
It is, if you have absolute control over the calling environment.
Is it possible to somehow create this environment variable inside
python script which will be avaibale even after the script exits. In
otherwords, after I run my script, if I do a "echo $name" in my
shell, it should return the value "vivek"


Here is an example Python script:

--------------------------------------------------------
import sys

name = sys.stdin.readline()
print "export name=%s" % name.strip()
--------------------------------------------------------

If you call it like this:

bash$ $(python examplescript)

It'll change the 'name' variable of your shell. It's not really a
generic nor an elegant way of doing this. Heck, it even depends on the
type of shell you're using. If it suits your needs, be happy ;-)

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Jul 21 '05 #3
On Mon, 11 Jul 2005 20:23:07 -0000, Grant Edwards <gr****@visi.com>
declaimed the following in comp.lang.python:
On 2005-07-11, Vivek Chaudhary <vi*******@yahoo.com> wrote:
Is it possible to set an environment variable in python script whose
value is retained even after the script exits.
No, not in Unix/Linux. In VMS I think there is.


And in the much maligned and ancient AmigaOS -- where there were
"local" (process specific) environment variables and global/system
environment variables. Locals were kept in process memory. Globals,
however, where kept in ENV: (for the VMS types, that would be equivalent
to a systemwide logical name into the file system). Each variable was a
separate text file...

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 21 '05 #4
[Vivek Chaudhary]
Is it possible to set an environment variable in python script whose
value is retained even after the script exits.


There is an indirect approach:
http://aspn.activestate.com/ASPN/Coo.../Recipe/159462
Raymond

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
20942
by: Christian | last post by:
Another question from a not even newbie: In Unix you can set an environment variable with the command export PYTHONPATH but I would like to set the variable from at .py script. So my question...
13
2998
by: Jimmy Cracker | last post by:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: main(int argc, char *argv) { char *var; var = (char...
1
2444
by: Bonj | last post by:
Hi My application installs a front-end GUI, which runs code when buttons are clicked. It also installs a command-line utility, that is a console application. They are both installed to the...
4
39045
by: | last post by:
Hi all, I am trying to append a certain string to the PATH environment variable programmatically. I am able to read what is in the variable using the System.Environment method...
3
5676
by: Strauss | last post by:
Hi: I'm setting the INCLUDE environment variable, but VC is not searching it for header files (I've checked it with filemon). I've tried with user variable, machine variable, rebooted the...
6
5318
by: yaron | last post by:
Hi, my application use environment variable, let call it FOO. how can i add the FOO environment variable to my project or my solution, so the line string foo =...
0
1965
by: Joe HM | last post by:
Hello - I am putting together a little ConsoleApplication that is supposed to check for an Environment Variable and create it if it does not exist. I found some code that will add a new...
0
1276
by: mirandacascade | last post by:
Apologies in advance for what I'm guessing may be a trivial question. Assume the following: 1) multi-user environment 2) standard (i.e. not a class module) module with: Public strSample as...
4
7485
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment...
4
16560
by: vkbishnoi | last post by:
I need to create an environment variable for another local user in windows. For example, say suppose there are 2 users in the system (User1 and User2). Currently User1 is logged in the system. Now Is...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.