473,231 Members | 1,803 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,231 software developers and data experts.

Saving parameters between Python applications?

I'm trying to do the following. I have a Python application that is
run:

python app1.py --location=c:\test1

What I want to do is save the location parameter, so I can then do (in
the same window):

python app2.py

And have app2.py automatically have access to the value of "location".

Now, the difficult part is, that in another window I want to do:

python app1.py --location=c:\test2
python app2.py

And have app2.py automatically get c:\test2 as the location. So the
two windows (consoles) are isolated from each other.

I thought I could use os.environ, but that doesn't save the variable
for applications that are run afterwards in the same window.

Any suggestions?

Thanks

Sep 16 '07 #1
14 1403
On 9/16/07, Stodge <st****@gmail.comwrote:
python app1.py --location=c:\test1
What I want to do is save the location parameter, so I can then do (in
the same window):
python app2.py
And have app2.py automatically have access to the value of "location".
Do app1.py to save a pickle of the value you want app2 to read.

--
Sebastián Bassi (セバスティアン). Diplomado en Ciencia y Tecnolog*a.
Curso Biologia molecular para programadores: http://tinyurl.com/2vv8w6
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
Sep 16 '07 #2
Good idea, but I can't guarantee that the two scripts will be run from
the same directory - so where to store the pickle?

On Sep 16, 5:25 pm, "Sebastian Bassi" <sba...@clubdelarazon.org>
wrote:
On 9/16/07, Stodge <sto...@gmail.comwrote:
python app1.py --location=c:\test1
What I want to do is save the location parameter, so I can then do (in
the same window):
python app2.py
And have app2.py automatically have access to the value of "location".

Do app1.py to save a pickle of the value you want app2 to read.

--
Sebastin Bassi ( ). Diplomado en Ciencia y Tecnologa.
Curso Biologia molecular para programadores:http://tinyurl.com/2vv8w6
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
Sep 17 '07 #3
On 9/17/07, Stodge <st****@gmail.comwrote:
Good idea, but I can't guarantee that the two scripts will be run from
the same directory - so where to store the pickle?
It doesn't matter if is the same directory or not, as long as both
programs has access to the pickle file (one program should have write
access and the other program should have at least read access).

--
Sebastián Bassi (セバスティアン). Diplomado en Ciencia y Tecnolog*a.
Curso Biologia molecular para programadores: http://tinyurl.com/2vv8w6
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
Sep 17 '07 #4
Stodge a crit :
I'm trying to do the following. I have a Python application that is
run:

python app1.py --location=c:\test1

What I want to do is save the location parameter, so I can then do (in
the same window):

python app2.py

And have app2.py automatically have access to the value of "location".

Now, the difficult part is, that in another window I want to do:

python app1.py --location=c:\test2
python app2.py

And have app2.py automatically get c:\test2 as the location. So the
two windows (consoles) are isolated from each other.

I thought I could use os.environ, but that doesn't save the variable
for applications that are run afterwards in the same window.

Any suggestions?
May use simple file in known place:
$HOME/.myprefs
$HOME/.conf/myprefs

Or host specific configuration API:
WindowsRegistry HKEY_CURRENT_USER\Software\MySociety\MyApp\myprefs
See os.getenv, and _winreg Windows specific module.
See also standard ConfigParser module
Hope you know how to read/write files.

Sep 17 '07 #5
Stodge a crit :
I'm trying to do the following. I have a Python application that is
run:

python app1.py --location=c:\test1

What I want to do is save the location parameter, so I can then do (in
the same window):

python app2.py

And have app2.py automatically have access to the value of "location".

Now, the difficult part is, that in another window I want to do:

python app1.py --location=c:\test2
python app2.py

And have app2.py automatically get c:\test2 as the location. So the
two windows (consoles) are isolated from each other.

I thought I could use os.environ, but that doesn't save the variable
for applications that are run afterwards in the same window.

Any suggestions?
Yes : pass the same arg to both app1.py and app2.py !-)

Braindead, I know, but still the simplest solution.
Sep 17 '07 #6
You're probably right!

Thanks all. :)

On Sep 17, 10:15 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
Stodge a crit :
I'm trying to do the following. I have a Python application that is
run:
python app1.py --location=c:\test1
What I want to do is save the location parameter, so I can then do (in
the same window):
python app2.py
And have app2.py automatically have access to the value of "location".
Now, the difficult part is, that in another window I want to do:
python app1.py --location=c:\test2
python app2.py
And have app2.py automatically get c:\test2 as the location. So the
two windows (consoles) are isolated from each other.
I thought I could use os.environ, but that doesn't save the variable
for applications that are run afterwards in the same window.
Any suggestions?

Yes : pass the same arg to both app1.py and app2.py !-)

Braindead, I know, but still the simplest solution.

Sep 17 '07 #7
On Sep 17, 6:39 am, Laurent Pointal
May use simple file in known place:
$HOME/.myprefs
$HOME/.conf/myprefs

Or host specific configuration API:
WindowsRegistry HKEY_CURRENT_USER\Software\MySociety\MyApp\myprefs

See os.getenv, and _winreg Windows specific module.
See also standard ConfigParser module

Also, os.path offers expanduser(). The following is reasonably
portable:

import os

user_home_dir = os.path.expanduser("~")
--
--Bryan

Sep 17 '07 #8
os.path.expanduser isn't an option; I need each console/window to
maintain different values which I wouldn't get from saving to a user's
home directory. Unless I used a different file for each console/window
but that just gets me into the same situation I'm already in. I think
the only option is to set environment variables using another script.
I'm really surprised and disapponited by this.

One option I thought of but haven't investigated, is the ability to
get the parent (i.e. console's) process id and use that to create a
file somewhere. Not sure if this is even possible.

On Sep 17, 4:29 pm, bryanjugglercryptograp...@yahoo.com wrote:
On Sep 17, 6:39 am, Laurent Pointal
May use simple file in known place:
$HOME/.myprefs
$HOME/.conf/myprefs
Or host specific configuration API:
WindowsRegistry HKEY_CURRENT_USER\Software\MySociety\MyApp\myprefs
See os.getenv, and _winreg Windows specific module.
See also standard ConfigParser module

Also, os.path offers expanduser(). The following is reasonably
portable:

import os

user_home_dir = os.path.expanduser("~")

--
--Bryan

Sep 18 '07 #9
Stodge a crit :
os.path.expanduser isn't an option; I need each console/window to
maintain different values which I wouldn't get from saving to a user's
home directory. Unless I used a different file for each console/window
but that just gets me into the same situation I'm already in. I think
the only option is to set environment variables using another script.
I'm really surprised and disapponited by this.
Note that it's *not* a Python issue. You'd have the same problem with
any other language.

Sep 18 '07 #10
Stodge wrote:
os.path.expanduser isn't an option; I need each console/window to
maintain different values which I wouldn't get from saving to a user's
home directory. Unless I used a different file for each console/window
but that just gets me into the same situation I'm already in. I think
the only option is to set environment variables using another script.
I'm really surprised and disapponited by this.
you can't do that either. It's the principle behind environment-vars that
you can't alter the ones of your parent process.

That's the reason why environment-changes must be done by using "source":
# source my_script

where my_script contains e.g.

export FOO="bar"
If you can have your user alter his/her .bashrc, you might consider creating
a environtment-variable in there that the subsequent script invocations
refer to. Like this:

# .bashrc
export SESSION=<create some unique name using e.g. date>

Then in the python-scripts you can use SESSION as a common prefix
into /tmp-residual files or such thing.

Diez
Sep 18 '07 #11
Stodge wrote:
os.path.expanduser isn't an option; I need each console/window to
maintain different values which I wouldn't get from saving to a user's
home directory. Unless I used a different file for each console/window
but that just gets me into the same situation I'm already in. I think
the only option is to set environment variables using another script.
I'm really surprised and disapponited by this.
That's a sign of your inexperience, then. As someone has already pointed
out, this is nothing to do with Python.

Under UNIX/Linux you could use the $$ variable to construct a filename
specific to a particular shell process and put it in the environment,
but I'm not aware of a similar feature in Windows. This is probably a
sign of *my* inexperience :-)
One option I thought of but haven't investigated, is the ability to
get the parent (i.e. console's) process id and use that to create a
file somewhere. Not sure if this is even possible.
You might be able to write a Python program to access it :-)

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

Sep 18 '07 #12
I wrote a small C program in Linux and used setenv() from stdlib and
it modified the console's environment. I can also modify the console's
environment from a DOS batch file, so why not in Python?

Guess I'm inexperienced and I just don't get it. :)

On Sep 18, 11:48 am, Steve Holden <st...@holdenweb.comwrote:
Stodge wrote:
os.path.expanduser isn't an option; I need each console/window to
maintain different values which I wouldn't get from saving to a user's
home directory. Unless I used a different file for each console/window
but that just gets me into the same situation I'm already in. I think
the only option is to set environment variables using another script.
I'm really surprised and disapponited by this.

That's a sign of your inexperience, then. As someone has already pointed
out, this is nothing to do with Python.

Under UNIX/Linux you could use the $$ variable to construct a filename
specific to a particular shell process and put it in the environment,
but I'm not aware of a similar feature in Windows. This is probably a
sign of *my* inexperience :-)
One option I thought of but haven't investigated, is the ability to
get the parent (i.e. console's) process id and use that to create a
file somewhere. Not sure if this is even possible.

You might be able to write a Python program to access it :-)

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

Sep 20 '07 #13
On 9/16/07, Stodge <st****@gmail.comwrote:
I'm trying to do the following. I have a Python application that is
run:

python app1.py --location=c:\test1

What I want to do is save the location parameter, so I can then do (in
the same window):

python app2.py

And have app2.py automatically have access to the value of "location".

Now, the difficult part is, that in another window I want to do:

python app1.py --location=c:\test2
python app2.py

And have app2.py automatically get c:\test2 as the location. So the
two windows (consoles) are isolated from each other.

I thought I could use os.environ, but that doesn't save the variable
for applications that are run afterwards in the same window.
Use a value based on your current tty. I don't know how to get this
value in Python but you could just shell 'tty' and grab the output.

Or, to get your parent process's pid, use os.getppid().

Then, use a temporary file whose name is based on the above info.
Sep 20 '07 #14
os.getppid() isn't cross platform. I don't think it works on Windows.
I think I'll just create a simple shell script (BAT or Bash) for each
platform as needed.

Thanks

On Sep 20, 3:17 pm, David <wizza...@gmail.comwrote:
On 9/16/07, Stodge <sto...@gmail.comwrote:
I'm trying to do the following. I have a Python application that is
run:
python app1.py --location=c:\test1
What I want to do is save the location parameter, so I can then do (in
the same window):
python app2.py
And have app2.py automatically have access to the value of "location".
Now, the difficult part is, that in another window I want to do:
python app1.py --location=c:\test2
python app2.py
And have app2.py automatically get c:\test2 as the location. So the
two windows (consoles) are isolated from each other.
I thought I could use os.environ, but that doesn't save the variable
for applications that are run afterwards in the same window.

Use a value based on your current tty. I don't know how to get this
value in Python but you could just shell 'tty' and grab the output.

Or, to get your parent process's pid, use os.getppid().

Then, use a temporary file whose name is based on the above info.

Oct 14 '07 #15

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

Similar topics

4
by: David Stockwell | last post by:
Hi, In java/jsp I can pass parameters to my python script on a webpage by doing something like this: http://somewhere.org/mypage.jsp?parm1=something&parm2=another How do I do that with...
4
by: Daves | last post by:
I am saving to database a result from multi-line textbox. The database of course wants \x escape codes, not the invisible ones. Is there any easy - one line code - way to do this (c#) eg by...
2
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is...
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
0
by: Xah Lee | last post by:
In this article, i explain how the use of bit masks is a hack in many imperative languages. Often, a function will need to take many True/False parameters. For example, suppose i have a function...
9
by: Wingot | last post by:
Hey, I am using Visual Studio 2008 Beta 2 for some application development in C#, but I presume that the following question applies equally well to any environment.
1
by: romcab | last post by:
Hi guys, I would like to ask your help about saving in ado.net. I was able to update it only on the display but when I check the database, it is not updated. I paste below my code and hopefully...
3
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly...
1
by: Stef Mientki | last post by:
Gabriel Genellina wrote: Didn't work for me winXP-SP2, even after a restart :-( But anyway thanks for the effort. cheers, Stef Mientki
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.