IDLE Python and Environment Variables

T

Tristan

Hello community:
I post this because I could not find satisfactory answers in the posts
generated by this nice group.
I work on winXP. I have many little python applications in different
folders, each application can share or not other objects located in the

same or other folders.
The way I work to use these applications is:
1) For almost everyone, I execute a corresponding ".bat file" into

which I define and/or include values for some "temporal"
environment variables that let me find all the objects that the
selected application uses. Sometimes I include in the .bat file the
execution of the application, but generally I leave in a prompt status,

ready to invoke python or some dos commands.
2) When I close the command prompt window, there are no traces of
my
enviroment variables in my windows system (that is right). Only the
default windows environment variables remain.

I tried to do the same with the IDLE (and I imagine tha same occurs
with Python command line), but I have the next problem:
I can not find in IDLE (or another app?) the way to previously define
and/or include automatically values for my "temporal" environment
variables as I do in the .bat files. The use of Control Panel -> System

-> Advanced is tedious to use as, my enviroment variables values are
"temporal".
Any advice, please???
 
G

Gabriel Genellina

1) For almost everyone, I execute a corresponding ".bat file" into

which I define and/or include values for some "temporal"
environment variables that let me find all the objects that the
selected application uses. Sometimes I include in the .bat file the
execution of the application, but generally I leave in a prompt status,

ready to invoke python or some dos commands.

What kind of environment variables? Those used by Python itself, like
PYTHONPATH? Or your own variables, like FOO_LOCATION=C:\My\Projects\Lib\Foo
2) When I close the command prompt window, there are no traces of
my
enviroment variables in my windows system (that is right). Only the
default windows environment variables remain.

I tried to do the same with the IDLE (and I imagine tha same occurs
with Python command line), but I have the next problem:
I can not find in IDLE (or another app?) the way to previously define
and/or include automatically values for my "temporal" environment
variables as I do in the .bat files.

So you write a .bat that:
- defines some variables
- calls your script.
It appears that your variables are some kind of configuration - in
this case it has more sense to put such configuration in another
place, like a config file, and forget about environment variables.
You can use the usual .ini Windows format and read it with
ConfigParser. You can pass your script the name of the ini file to
read - this would be the equivalent of using different .bat files to
call the same script.
This way it doesn't matter whether you invoke your application using
python command line, or inside IDLE, or inside another environment.


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
T

Tristan

Thanks Gabriel.
What kind of environment variables? Those used by Python itself, like
PYTHONPATH? Or your own variables, like FOO_LOCATION=C:\My\Projects\Lib\Foo

I need to add to PYTHONPATH and other enviroment variables asked, for
example, by DJANGO or other python products.
It appears that your variables are some kind of configuration - in
this case it has more sense to put such configuration in another
place, like a config file, and forget about environment variables.
You can use the usual .ini Windows format and read it with
ConfigParser. You can pass your script the name of the ini file to
read - this would be the equivalent of using different .bat files to
call the same script.
This way it doesn't matter whether you invoke your application using
python command line, or inside IDLE, or inside another environment.

I considered to use it, thanks!! Incidentally (beg your pardon if it
sounds to ignorance), can I define Environment variables in a config
file and then apply to my python program?

Thanks!!!
 
G

Gabriel Genellina

I considered to use it, thanks!! Incidentally (beg your pardon if it
sounds to ignorance), can I define Environment variables in a config
file and then apply to my python program?

Yes, read them from the config file and then use os.environ['name']=value
See http://docs.python.org/lib/os-procinfo.html


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top