Environmental Variables

S

Sathyaish

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.
 
D

Diez B. Roggisch

Sathyaish said:
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
 
F

Fredrik Lundh

Sathyaish said:
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>
 
S

Sathyaish

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:

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:

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.
 
F

Fredrik Lundh

Sathyaish said:
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>
 
D

Diez B. Roggisch

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
 
D

Duncan Booth

Sathyaish said:
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.
 
S

Sathyaish

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.
 
J

John Salerno

Sathyaish said:
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?
 
D

Dennis Lee Bieber

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 :)
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.
--
 
D

Dennis Lee Bieber

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:
Would the information in section 3.29 of the library reference
manual (at least, it's that on my 2.3 install) be of use... section on
site customization.
--
 
D

Diez B. Roggisch

Dennis said:
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
 
D

Dennis Lee Bieber

Well, the amiga lacked a MMU - so you could do _anything_ if you really
wanted :)
I think the '040 supported that (MMU) -- though still with a flat
address space shared among all processes. But that flat address space is
also what made ARexx so good at IPC (forget all these in/out pipes on
single commands)...
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.
My change-over occurred when I couldn't find a replacement monitor
that could synch between NTSC and 40KHz -- it was cheaper to buy a
Dell...
--
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top