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

Dave Angel d at davea.name
Mon Dec 24 00:19:18 EST 2012


On 12/23/2012 04:42 PM, prilisauer at googlemail.com wrote:
> Okay, I try to publish this sample, and yes it's not a working piece of code, but I try to "draw" my problem that way. As you will see, I load modules, create cursor,... in the main.py. 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
You're miles from being ready to worry about "the same time."  Don't
start threading till you can get a simple multi-module program understood.
> I hope really found the right "wording". thank to all your help.
>
>
> main.py

For some reason you capitalize all those filenames, so you're stuck with
unpythonic module names.  If you want your code readable, use lowercase
for module name, and Capitalized for class name.

> import HomeLog # LogHandler
> import HomeSocketServer # Threaded TCP Socket Server
> import HomeDatastore # SQLite DB
> import HomeDaliServer # Connects to USB Device
> import HomeScheduler # Advanced scheduler functions
>
>
> # Attach Loghandler
> Loghandler = HomeLog.Logging()
> # Attach SocketServer
> HomeSocketServer.HomeSocketServerStart()
>
> # Attach Scheduler
> HomeSched = HomeScheduler.HomeScheduler()
> HomeSched.SchedulerStart()
> HomeSched.SchedulerJobs()
>
> # Attach Datastore
> Datastore=HomeDatastore.HomeDBStore()
> Datastore=Datastore.Startup()
>
> #Attach Dali Driver
> Dali=HomeDaliServer.Startup()
> # This is a "Sample" that builds 2byte Cmd and transmits it on bus
> PowerOnLamp1=Dali.send(0,0,1,80)
>
> ###############################################################
> HomeDaliServer.py
import HomeDatastore
> ........
> def send (self,DaliAdress,RequestType,Request,RequestValue):
Nobody's going to be able to understand your code if you persist in
using self in unpythonic ways.  It's used as the first argument of a
class method. Period.
> # Problemsection1:
> # Here it's getting Interesting
> # We're at the HomeDaliServer, and now I want to use QuerySqlite() in the file HomeDatastore.py
So call it:
       firstarg = whatever * RequestType
       secondarg = something different + RequestValue
       result = HomeDatastore.QuerySqlite(firstarg, secondarg)
> ###############################################################
> HomeScheduler.py
Where are your import statements?  No module automatically sees imports
that were done elsewhere.  Import what you need in a module.
> # Problemsection2:
> # If new workerthread is started, Informations must be queried using QuerySlite() and also update data
I don't see any 'update data' function anywhere, but if you want to call
QuerySqlite, you need to call it:
      thisresult = HomeDatastore.QuerySqlite(him, her, theother)
>
> ###############################################################
> HomeDatastore.py
> def QuerySqlite():
You presumably mean
      def QuerySqlite(firstparam, secondparam):

since a function with no arguments is going to be stuck trying to use
globals, and that's not a good habit to get into.
> #doing something here..
    #doing something with those parameters, and only those parameters
> # returning Data
>
> ###############################################################
>


-- 

DaveA




More information about the Python-list mailing list