471,350 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Creating a shared object in python

Is there a way to create a shared object in python?

Thx,

Edgar
Jul 31 '07 #1
3 3999
On Jul 31, 2:37 pm, "Delgado, Edgardo CIV NAVAIR 4.1.4.3"
<edgardo.delg...@navy.milwrote:
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

Jul 31 '07 #2
Il Tue, 31 Jul 2007 15:37:26 -0400, Delgado, Edgardo CIV NAVAIR 4.1.4.3
ha scritto:
Is there a way to create a shared object in python?

Thx,

Edgar
Usually object are shared in Python. i.e.

# a list
l = [ 1 , 2 , 3 ]

# a list containing l
m = [ l, 4, 5 ] # now m is [ [1,2,3] , 4 , 5 ]

# ok, let's change l
l[0] = 10

# now m is changed
# NOW m is [ [10,2,3] , 4 , 5 ]
Jul 31 '07 #3
Delgado, Edgardo CIV NAVAIR 4.1.4.3 wrote:
Is there a way to create a shared object in python?
What's a shared object? Do you mean IPC or .so libraries, or
something different?

Regards,
Björn

--
BOFH excuse #404:

Sysadmin accidentally destroyed pager with a large hammer.

Jul 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Francisco Miguel Montenegro Montes | last post: by
3 posts views Thread by Pro Grammer | last post: by
19 posts views Thread by Dr Mephesto | last post: by
5 posts views Thread by Tim | last post: by
reply views Thread by abarun22 | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.