[Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Alexander Blinne
news at blinne.net
Sat Dec 22 14:29:49 EST 2012
Am 22.12.2012 19:10, schrieb prilisauer at googlemail.com:
> It's for me a view of top side down, but how could the midlevel comunicate to each oter... "not hirachical"
You could use something like the singleton pattern in order to get a
reference to the same datastore-object every time Datastore.Datastore()
is called. But you still need to close the connection properly at some
point, propably using a classmethod Datastore.close().
e.g.:
main.py:
from Datastore import Datastore
from ModbusClient import Modbus
from DaliBusClient import DaliBus
def main():
modbus = Modbus(...)
dalibus = DaliBus(...)
modbus.read_data_and_save_to_store()
dalibus.read_data_and_save_to_store()
Datastore.close()
if __name__=="__main__":
main()
ModbusClient.py:
import Datastore
class Modbus(object):
def read_data_and_save_to_store(self):
datastore = Datastore.Datastore()
#do something with datastore
More information about the Python-list
mailing list