Creating a shared object in python

kyosohma at gmail.com kyosohma at gmail.com
Tue Jul 31 15:57:05 EDT 2007


On Jul 31, 2:37 pm, "Delgado, Edgardo  CIV NAVAIR 4.1.4.3"
<edgardo.delg... at navy.mil> wrote:
> Is there a way to create a shared object in python?
>
> Thx,
>
> Edgar

You can save variables in a separate module. Something like this
structure works quite well:

<code>
# shared.py
# shared variables / object
someNum = 0
</code>

<code>
# first module
import shared
x = shared.someNum
# do something
x = 5
</code>

<code>
# second module
import shared
y = shared.someNum
</code>

Basically as the code is called, be it a dialog from a main gui or
whatever, it updates this variable that is kind of held "out there" in
memory. Thus, it is available for and other running modules that
import it. It's kind of hard to get your mind around at first, but
I've used it before for some cool programming magic.

Mike




More information about the Python-list mailing list