473,698 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\tes t1

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:\tes t2
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
14 1432
Stodge wrote:
os.path.expandu ser 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.expandu ser 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...@holdenwe b.comwrote:
Stodge wrote:
os.path.expandu ser 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.c omwrote:
I'm trying to do the following. I have a Python application that is
run:

python app1.py --location=c:\tes t1

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:\tes t2
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.c omwrote:
I'm trying to do the following. I have a Python application that is
run:
python app1.py --location=c:\tes t1
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:\tes t2
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
3544
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 python? Also would I need to import a special module so I could grab them off the
4
1479
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 String.Format() ?
2
3995
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 below and of course it's not working properly because my web page which displays the resulting image from the database is not showing the image. I **think** the problem is in my converting the bitmap back to a byte array. If I change my code back...
6
3510
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 --> Save) in MS Photo Editor, the file is automatically shrunk in size to 81 KB's. When doing the same thing in MS Paint, the file is shrunk to 54 KB's. The file has the same number of pixels after both saves (as expected). My question follows...
0
2094
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 that can draw a rainbow, and each color of the rainbow can be turned on or off individually. My function specification can be of this form: “rainbow(red, orange, yellow, green, blue, violet, purple)”. Each parameter is a true or false value....
9
2393
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
1334
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 you can help me. using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient;
3
2465
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 the binary data for the file. I can sucessfully take the files out of the databse again and display them in a data grid. I would like to resize the submitted file to a fixed size (say 180 x 120) before I upload it to the database and do this without...
1
971
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
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.