473,386 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Environmental Variables

In which physical file are the python environmental variables located?
I know I can access them using the:
os.environ.get('PYTHONSTARTUP')

or

os.environ.get('PYTHONPATH')
to get their values. But out of the program, if I need to look at them
and alter their values, where do I find them? Are they the OS
environmental variables as I suspect? If they are, then I'll find them
with the other OS environ variables in My
Computer->System->Properties->Advanced->Environmental Variables.

But I checked that place and did not find any default values for them.

Mar 13 '06 #1
9 10806
Sathyaish wrote:
In which physical file are the python environmental variables located?
I know I can access them using the:
os.environ.get('PYTHONSTARTUP')

or

os.environ.get('PYTHONPATH')
to get their values. But out of the program, if I need to look at them
and alter their values, where do I find them? Are they the OS
environmental variables as I suspect? If they are, then I'll find them
with the other OS environ variables in My
Computer->System->Properties->Advanced->Environmental Variables.

But I checked that place and did not find any default values for them.


They aren't necessarily stored somewhere - except in memory. You can open a
cmd-prompt and do something like

set FOO "bar"

(syntax may vary, I'm a UNIX-guy)

Then you will be able to access this variable from a process - like python.
But it is nowhere saved.

Diez
Mar 13 '06 #2
Sathyaish wrote:
In which physical file are the python environmental variables located?
I know I can access them using the:
os.environ.get('PYTHONSTARTUP')

or

os.environ.get('PYTHONPATH')
to get their values. But out of the program, if I need to look at them
and alter their values, where do I find them? Are they the OS
environmental variables as I suspect?
yes.
If they are, then I'll find them with the other OS environ variables in My
Computer->System->Properties->Advanced->Environmental Variables.
yes, provided that they've been set, and set via that dialogue (and not
by some startup script or other mechanism).
But I checked that place and did not find any default values for them.


there are no default values for the variables you mention.

(as written, the environ.get call returns None if the variable is not set)

</F>

Mar 13 '06 #3
Thanks for the replies.

I am trying to have a startup file execute everytime I launch the
interpreter. So, for a test, I wrote a small file I called
"Sathyaish.py". The contents of the file were simply:

# ! This is my new start-up file.

print "Sathyaish is the best."
Then, in the interpreter, on its prompt, I said:
os.environ['PYTHONSTARTUP'] = 'C:\\Sathyaish.py'

It didn't complain. I tested it immediately. On the same interpreter
instance, I said:
import os
os.environ.get('PYTHONSTARTUP')
It gave me back 'C:\Sathyaish.py'. I didn't close that interpreter. I
left it open and launched a new instance of the interpreter. In this I
queried the same:

import os
os.environ.get('PYTHONSTARTUP')

None

was what I got. I checked the at DOS prompt (cmd) for PYTHONSTARTUP,
and I got an 'unrecognized program/command/batch file' interrupt.

What's the deal with environmental variables? Are they specific to an
interpreter session? That shouldn't be.

Mar 13 '06 #4
> was what I got. I checked the at DOS prompt (cmd) for PYTHONSTARTUP,
and I got an 'unrecognized program/command/batch file' interrupt.

What's the deal with environmental variables? Are they specific to an
interpreter session? That shouldn't be.


Yes they are - and yes, it should be that way. A process inherits the
environment of its parent. It can set its own environment, and if it forks
children, these will see that. But there is no way for a process to alter
the environment of its parent, let alone some arbitrary other process. This
is an OS-limitation (or feature) - so if you absolutely have to convince
somebody that it is bad, try Redmond :)

DIez
Mar 13 '06 #5
Sathyaish wrote:
What's the deal with environmental variables? Are they specific to an
interpreter session? That shouldn't be.


If you think that then complain to Microsoft, or even the people who
developed Unix since that is what Microsoft based their environment
variables on.

Environment variables work the same way in Python as they do in any other
process: any process can modify its own environment variables and pass
those changes down to other processes which it starts, but no process can
modify the environment of its parent process or any other process in the
system.
Mar 13 '06 #6
Sathyaish wrote:
What's the deal with environmental variables? Are they specific to an
interpreter session?
they're copied from the parent process when a new process is started,
and any changes to them are local to the process.
That shouldn't be.


that's how environment variables work, on all platforms.

</F>

Mar 13 '06 #7
I recall now, the shells in Unix - a child inherited the variables
declared in its parent but not vice-versa. It works the same way in
DOS. So, I wasn't seeing it clearly earlier. I am seeing it clearly
now. I was imagining that the PYTHONPATH had some default value on
installation and was expecting to see it. And since it was an
*environmental* variable I was setting, I just expected it to turn up
in the entire environment, totally forgetting the scope of the
environment I was declaring it in - a process and not an OS.

Thanks.

Mar 13 '06 #8
Sathyaish wrote:
In which physical file are the python environmental variables located?
I know I can access them using the:
os.environ.get('PYTHONSTARTUP')

or

os.environ.get('PYTHONPATH')
to get their values. But out of the program, if I need to look at them
and alter their values, where do I find them? Are they the OS
environmental variables as I suspect? If they are, then I'll find them
with the other OS environ variables in My
Computer->System->Properties->Advanced->Environmental Variables.

But I checked that place and did not find any default values for them.


As far as PYTHONPATH goes, I added that one manually to my list of
environment variables. As far as I know, it's not there by default.

Now, can someone tell me if adding it manually interferes with anything
else Python itself is doing?
Mar 13 '06 #9
Dennis Lee Bieber wrote:
The Amiga did have a means for such... It differentiated between
local and global environment variables. Locals were kept in a process
memory structure and behaved as they do on most other OSs... Globals,
however, were short files maintained in ENV: (a logical name to a disk
directory); so any process changing the file contents (whether
explicitly using open/write/close, or implicitly with SETENV name
value) would be visible in all other processes. Locals were defined
using just SET name value.


Well, the amiga lacked a MMU - so you could do _anything_ if you really
wanted :)

And I consider such a "feature" risky - think of buffer-overflows which
could be provoked in running processes with other user-rights.

But nonetheless I loved the AMIGA and its OS - actually I only moved to a PC
in 96 when I discovered that there was a OS (Linux) that appealed to me in
similar ways as the AMIGA-os did.

Diez
Mar 13 '06 #10

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

Similar topics

1
by: Bruce Lehmann | last post by:
Hi, I've installed Apache (WAMP install) so I can edit and test my web site on my home computer. In general php code seems to work, but I can't access Apache variables such as PATH or...
1
by: Ric | last post by:
thx for the help. im having problems with java and jsp. i think im not settup up the enviornmental variables right in w2k advanced tab. im using a wrox book, but the wrox book references a servlet...
15
by: Casanova | last post by:
Hello!! how can i get all the details of the environmental variables. If i use getenv, i will have to specify the name of the variable. for intsance i will have to give getenv("PATH") How can...
2
by: Steven | last post by:
I have an asp.net application written in VB.net. I want to access a client side environment variable. For instance, we set an environment variable for the UserName. So, I write the code for...
4
by: Shiraz | last post by:
Hi I'm using Visual Studio Installer to make my installer, and have not as yet figured out a straightforward way to use it to set environmental variables. Amongst the various things I tried, I'm...
2
by: Kourosh | last post by:
I'm just wondering, is there a way I could use an environmental variable in an XML file to specify the path of its XSL file? something like <?xml-stylesheet type="text/xsl"...
0
by: Mike | last post by:
Hi I regularly install DB2 Runtime Lite to connect to a database, when I install DB2 Runtime Lite in need to define some environmental variables in the System Variables option , the variable is...
2
Curtis Rutland
by: Curtis Rutland | last post by:
I want to get the actual physical path for some of the Windows Environmental Variables. If I typed %TEMP% into the Run prompt on Vista, I'd go to the folder: C:\Users\username\AppData\Local\Temp ...
9
by: iavian | last post by:
Hi all , I want to set a env variable in a C program? . Not through shell env variables. Any help? Thanks Vijay
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...

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.