[Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

Alexander Blinne news at blinne.net
Sat Dec 22 18:26:43 CET 2012

Am 22.12.2012 13:45, schrieb prilisauer at googlemail.com:
> Ps.: The Socket, the DB has to be kept allways open, because of it's Server functionality, A lot of Sensors, Timers, User interaction, must recived , Calculated, etc so a reaction must be send in about 16~100 ms, different modules opens and closes Sockets or files, could result in a dead situation.
> Or do i didn't see any Tree's in the Wood?

I would strongly recommend an object oriented view:

Suppose Datastore.py contains a Class Datastore. You can instantiate
that class once in the beginning of your main file and the resulting
object has methods to store and retrieve data in/from the store.

ModbusClient.py contains a Class Modbus. This also can be instantiated
just once which opens a TCP connection to be used many times and you can
hand over a reference to the Instance of Datastore you created earlier,
so it can speak with the Datastore. The object has methods to do the
things you want it to do.

The Same for DaliBusClient.

Now your main.py could look something linke

from Datastore import Datastore
from ModbusClient import Modbus
from DaliBusClient import DaliBus

def main():
    datastore = Datastore(...)
    modbus = Modbus(..., datastore)
    dalibus = DaliBus(..., datastore)


if __name__=="__main__":

More information about the Python-list mailing list