[PyKDE] Static member functions

Sundance sundance at ierne.eu.org
Tue Dec 14 00:37:52 GMT 2004


I heard Hihn, Jason said:

> How can I do this in python?

It may be I'm not getting your question, but... What's the problem 
exactly? You can have global objects (which includes functions) all you 
want, really.

Example:

---[ globalstuff.py ]--------------------------------------------------
data = None
-----------------------------------------------------------------------

---[ A.py ]------------------------------------------------------------
import globalstuff
def functionA():
  globalstuff.data = 42
-----------------------------------------------------------------------

---[ B.py ]------------------------------------------------------------
import globalstuff
def functionB():
  print "The global data contains:", globalstuff.data
-----------------------------------------------------------------------

---[ main.py ]---------------------------------------------------------
import globalstuff

from A import functionA
from B import functionB

# Set the global bit of data with functionA() from module A:
functionA()

# Print the global bit of data with functionB() from module B:
functionB()

# Set the global bit of data ourselves:
globalstuff.data = "Nobody expects the Spanish Inquisition!"

# Then print it with functionB() from module B:
functionB()

print "See, Jason? I don't understand what your problem is, exactly."
-----------------------------------------------------------------------

Does this answer your question?

-- S.




More information about the PyQt mailing list