By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,931 Members | 1,976 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,931 IT Pros & Developers. It's quick & easy.

IDLE Python and Environment Variables

P: n/a
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???

Jan 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
At Wednesday 10/1/2007 23:24, Tristan wrote:
>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

Jan 11 '07 #2

P: n/a
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!!!

Jan 11 '07 #3

P: n/a
At Thursday 11/1/2007 11:45, Tristan wrote:
>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

Jan 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.