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

Thomas Bach thbach at students.uni-mainz.de
Mon Dec 24 00:18:55 EST 2012


Hi there,

On Sun, Dec 23, 2012 at 01:42:14PM -0800, prilisauer at googlemail.com wrote:
> […] In the lower section you see, that the modules should execute
> sqls. In case It could occur that two queries occur at the same
> time.  PS: IT IS NOT A QUESTION ABOUT SQL, etc. I do not understand,
> how I could handle the part which is marked with Problemsection1 and
> Problemsection2

I actually do not understand the problem you are stating. But, did you
have a look at SQLAlchemy? If you are coping a lot with SQL it really
makes your life much easier and they also provide the necessary
mechanisms for threading.

> import HomeLog # LogHandler

Modules should be written all lower-case separated by underscores.

> # Attach Loghandler
> Loghandler = HomeLog.Logging()

Have a look at the logging module and tutorial. I don't know what is
in HomeLog.Logging, but this doesn't seem right. 

Variables defined at module level should be written all upper-case.

> # Attach SocketServer
> HomeSocketServer.HomeSocketServerStart()
> 
> # Attach Scheduler
> HomeSched = HomeScheduler.HomeScheduler()
> […]
> # This is a "Sample" that builds 2byte Cmd and transmits it on bus
> PowerOnLamp1=Dali.send(0,0,1,80)

You do all this on the module level? These things should go into
functions with proper names or at least into a 

if __name__ == '__main__':
    pass


> ###############################################################
> HomeDaliServer.py
> ........
> def send (self,DaliAdress,RequestType,Request,RequestValue):
> # Problemsection1:
> # Here it's getting Interesting
> # We're at the HomeDaliServer, and now I want to use QuerySqlite()
> in the file HomeDatastore.py

So, where's the problem?

# make sure not to introduce cyclic dependence here!
import home_data_store

def send (connection,DaliAdress,RequestType,Request,RequestValue):
    results = home_data_store.query_sqlite(connection, …)
    return results


> ###############################################################
> HomeScheduler.py
> # Problemsection2:
> # If new workerthread is started, Informations must be queried using
> QuerySlite() and also update data

So, here's a first sketch (untested):

def query():
    data = do_something()
    return data

def update(data):
    do_something_with(data)


> HomeDatastore.py
> def QuerySqlite():
> #doing something here..
> # returning Data

Have you read the Python tutorial by the way?

Regards,
	Thomas.



More information about the Python-list mailing list