Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
By the way i haven't add the Title because it's a german only book named "Python 3: Das umfangreiche Handbuch, Published by Galileo Computing" and also, because I've registered to first check if the Autor has allready published a update. Too many information's could ocurre in an avalanche I see a big failure: 1. I answer to quick -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Hello Steven, to "learn python" I've bought a book, and it's not a "thin" one :-) it's more a 788p. long documentation about python. BUT! I have to say: The autor started using the "self." argument at the chapter classes. So You've shown me the book descr. non "correct" way. Better using this book heating my home?! :-) Patrick -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Hey :-P I think I should rename the threads name into a new "Doc" project, I'm sure It won't take much time to fill a book with our knowledge. Thanks to Rick, you have Posted exactly what I wanted to ask. I know the that __variable = 'xyz' _variable = 'xyz' are used to make them private, but I haven't found it for methods. Thanks :) I also don't think you're off topic! It's a big grey scale :-) and for me the first post till the last one is a part of my "question" PEP, is nice, it tooks me a few days to get trough all your input and my code. Anyway is there also a best practice for naming? eg.: module_class_sub() or wording? eg.: socket: send() recv() -> recv is kept short. according PEP8?? It seems, my english slowly getting better again, If my colleagues would see what I'm writting here they won't belive me. I've worked at the Pharmaceutical IT and made Codereviews and programming for medical software. I still can't belive what I've forgotton the last two years. But still PEP etc. isn't far that hard written like pharm eu, usp, and 21CFR. Shame on me, but I will come back, after I've finished. BR -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Hello Dave, Thank you, for your help, I'll try my best. To all others, PLEASE be pleasant with my nescience, I'll tried to describe not a specific error at my Program. I'll tried to get rid of that missing link this sample is only theoretic, but the code really exists and is over 1000 lines long. I understood how to transmit data to a class, but I do not understood how that class could access an SQL object, that is allready opened at a other class without getting into troubles with sqlite. For my understood, the newsgroup isn't a place only to solve concrete problems. I think you're not only a "helpdesk" :-), If I'm at the wrong group to get some Ideas how to solve my "issues" Ps.: DaveA I don't know how to say it, but I treasure your great work here, giving such detailed good answers. PPs.: I know, that my codingstyle isn't that great, I've haven't programmed the last two years. You're welcome to guess what I've worked 8 years long. :-) you will laugh till you fall of your keyboard :-P PPPs.: I' will use that day to check out the PEP's and correct my coding style, and naming. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
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 I hope really found the right "wording". thank to all your help. main.py 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 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 ### HomeScheduler.py # Problemsection2: # If new workerthread is started, Informations must be queried using QuerySlite() and also update data ### HomeDatastore.py def QuerySqlite(): #doing something here.. # returning Data ### -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Thanks to all your answers, I have read a lot about namespaces, but still there's something I do not understood. I have tried your example but as I expected: line 13, in HandoverSQLCursor curs.execute("SELECT * FROM lager") AttributeError: 'builtin_function_or_method' object has no attribute 'execute' I will try my best to write tomorrow a sample as detailed as possible. Good evening -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
secondly, it is absolutely not bad meaned, but, why does people post, their personal meaning, but nothing about the "Posters" Problem? Everybody is free to read or not, but correcting the WWW could became a very very big task, (maybe it's easier to climb the 7 summits) Best Regards. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
By the way, I think I have found the correct "wording". for my understood, the "handover" of objects to imported modules doesn't work because, e.g. trying to hand-over an SQLite connection into a imported module, can't work because the "attributes" are not transfered. I'm sorry for my bad english, it's fascinating. 2 years ago I've written very large english technical documents for my company. As you can see, the last two years I've forgotten a lot and it tooks me some time to get back into. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Am Samstag, 22. Dezember 2012 20:29:49 UTC+1 schrieb Alexander Blinne: > Am 22.12.2012 19:10, schrieb: > > > 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 I Think I describe my Situation wrong, the written Project is a Server, that should store sensor data, perfoms makros on lamps according a sequence stored in the DB and Rule systems schould regulate home devices and plan scheduler jobs so on. The System Runs in a threated environment. It looks for me, like the limits are at the end of file. my core problem also the only one I have is: I don't know how to get over that limits and enable dataexchange like a backbone... -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Am Samstag, 22. Dezember 2012 18:26:43 UTC+1 schrieb Alexander Blinne: > Am 22.12.2012 13:45, schrieb: > > > 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) > > > > modbus.read_data_and_save_to_store() > > dalibus.read_data_and_save_to_store() > > > > if __name__=="__main__": > > main() Yes, My Project is allready > 1000 lines and even more,.. I have started writing it, each module after another ... I've got allready a lot of experience in other programming languages ( also I have worked as a programmer) But the question is, could communicate a DaliModul, Modbus,.. Etc with the backend db. It's for me a view of top side down, but how could the midlevel comunicate to each oter... "not hirachical" -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Am Samstag, 22. Dezember 2012 14:54:27 UTC+1 schrieb Peter Otten: > wrote: > > > > > I don't know, Python allways looks for me like a one script "File". But > > > there are big projects. like the the "Model of an SQL Server", using > > > coordinators no problems running threads and exchange Data through a > > > Backbone. I have searched a lot, but I havent find anything to write the > > > "core" splited up into modules and geting over the scopes etc. > > > > > > DO I have anything forgotten?! everything unclear?? :-P > > > > I think you have to step back and acquire some experience with a smaller, > > less complex project... investigating libraries on which you can base your > > efforts may also be a good idea. > > > > If the Perl program is well-structured there is no reason not to copy its > > architecture -- but I suspect you wouldn't want to migrate then. Yes, but my project couldn't be smaller, my core problem is how to exchange data between modules?!... -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Am Samstag, 22. Dezember 2012 13:38:11 UTC+1 schrieb prili...@googlemail.com: > Am Samstag, 22. Dezember 2012 12:43:54 UTC+1 schrieb Peter Otten: > > > wrote: > > > > > > > > > > > > > Hello, to all, > > > > > > > > > > > > > > I hope I can describe me problem correctly. > > > > > > > > > > > > > > I have written a Project split up to one Main.py and different modules > > > > > > > which are loaded using import and here is also my problem: > > > > > > > > > > > > > > 1. Main.py executes: > > > > > > > 2. Import modules > > > > > > > 3. One of the Modules is a SqliteDB datastore. > > > > > > > 4. A second module creates an IPC socket. > > > > > > > 5. Here is now my problem : > > > > > > > The IPC Socket should run a sub which is stored ad SqliteDB and > > > > > > > returns all Rows. > > > > > > > > > > > > > > Is there a elegant way to solve it? except a Queue. Is it possible to > > > > > > > import modules multiple?! > > > > > > > > > > > > If you import a module more than once code on the module level will be > > > > > > executed the first time only. Subsequent imports will find the ready-to-use > > > > > > module object in a cache (sys.modules). > > > > > > > > > > > > > I'm unsure because the open DB file at another > > > > > > > module. > > > > > > > > > > > > > > How is this solved in bigger projects? > > > > > > > > > > > > If I'm understanding you correctly you have code on the module level that > > > > > > creates a socket or opens a database. Don't do that! > > > > > > Put the code into functions instead. That will give the flexibility you > > need > > > > > > for all sizes of projects. For instance > > > > > > > > > > > > socket_stuff.py > > > > > > > > > > > > def send_to_socket(rows): > > > > > > socket = ... # open socket > > > > > > for row in rows: > > > > > > # do whatever it takes to serialize the row > > > > > > socket.close() > > > > > > > > > > > > database_stuff.py > > > > > > > > > > > > def read_table(dbname, tablename): > > > > > > if table not in allowed_table_names: > > > > > > raise ValueError > > > > > > db = sqlite3.connect(dbname) > > > > > > cursor = db.cursor() > > > > > > for row in cursor.execute("select * from %s" % tablename): > > > > > > yield row > > > > > > db.close() > > > > > > > > > > > > > > > > > > main.py > > > > > > > > > > > > import socket_stuff > > > > > > import database_stuff > > > > > > > > > > > > if __name__ == "__main__": > > > > > > socket_stuff.send_to_socket( > > > > > > database_stuff.read_table("some_db", "some_table")) > > > > Hello Thanks for that answer: > > I think I have to write it a bit larger, > > > > This isn't a real code, but it for better overview: > > main.py > > // \ \ > > --- > > Datastore | ModbusClient | DaliBusClient | Advanced Scheduler > > > > > > > > Main.py: > > import Datastore > > Datastore.startup() > > > > (Everything should run in threads) > > > > Datastore.py > > # Opens a SQLite DB > > # Contains Queries to serve data for other mods > > # Central point for updating / Quering etc. > > > > ModbusClient.py > > # Opens TCP connection to Modbus Device > > !!! Here it's interesting !!! > > This module contains predefined Queries and functions > > IF I START A FUNCTION a SQL should be executed in Datastore.py > > > > > > DaliBusClient.py > > #Lamps, etc. Functions. > > # Stored Informations should be kept in Datastore > > # Advanced scheduler > > > > > > I don't know, Python allways looks for me like a one script "File". But there > are big projects. like the the "Model of an SQL Server", using coordinators > no problems running threads and exchange Data through a Backbone. I have > searched a lot, but I havent find anything to write the "core" splited up > into modules and geting over the scopes etc. > > > > DO I have anything forgotten?! everything unclear?? :-P 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? Br -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Am Samstag, 22. Dezember 2012 12:43:54 UTC+1 schrieb Peter Otten: > wrote: > > > > > Hello, to all, > > > > > > I hope I can describe me problem correctly. > > > > > > I have written a Project split up to one Main.py and different modules > > > which are loaded using import and here is also my problem: > > > > > > 1. Main.py executes: > > > 2. Import modules > > > 3. One of the Modules is a SqliteDB datastore. > > > 4. A second module creates an IPC socket. > > > 5. Here is now my problem : > > > The IPC Socket should run a sub which is stored ad SqliteDB and > > > returns all Rows. > > > > > > Is there a elegant way to solve it? except a Queue. Is it possible to > > > import modules multiple?! > > > > If you import a module more than once code on the module level will be > > executed the first time only. Subsequent imports will find the ready-to-use > > module object in a cache (sys.modules). > > > > > I'm unsure because the open DB file at another > > > module. > > > > > > How is this solved in bigger projects? > > > > If I'm understanding you correctly you have code on the module level that > > creates a socket or opens a database. Don't do that! > > Put the code into functions instead. That will give the flexibility you need > > for all sizes of projects. For instance > > > > socket_stuff.py > > > > def send_to_socket(rows): > > socket = ... # open socket > > for row in rows: > > # do whatever it takes to serialize the row > > socket.close() > > > > database_stuff.py > > > > def read_table(dbname, tablename): > > if table not in allowed_table_names: > > raise ValueError > > db = sqlite3.connect(dbname) > > cursor = db.cursor() > > for row in cursor.execute("select * from %s" % tablename): > > yield row > > db.close() > > > > > > main.py > > > > import socket_stuff > > import database_stuff > > > > if __name__ == "__main__": > > socket_stuff.send_to_socket( > > database_stuff.read_table("some_db", "some_table")) Hello Thanks for that answer: I think I have to write it a bit larger, This isn't a real code, but it for better overview: main.py // \ \ --- Datastore | ModbusClient | DaliBusClient | Advanced Scheduler Main.py: import Datastore Datastore.startup() (Everything should run in threads) Datastore.py # Opens a SQLite DB # Contains Queries to serve data for other mods # Central point for updating / Quering etc. ModbusClient.py # Opens TCP connection to Modbus Device !!! Here it's interesting !!! This module contains predefined Queries and functions IF I START A FUNCTION a SQL should be executed in Datastore.py DaliBusClient.py #Lamps, etc. Functions. # Stored Informations should be kept in Datastore # Advanced scheduler I don't know, Python allways looks for me like a one script "File". But there are big projects. like the the "Model of an SQL Server", using coordinators no problems running threads and exchange Data through a Backbone. I have searched a lot, but I havent find anything to write the "core" splited up into modules and geting over the scopes etc. DO I have anything forgotten?! everything unclear?? :-P -- http://mail.python.org/mailman/listinfo/python-list
[Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)
Hello, to all, I hope I can describe me problem correctly. I have written a Project split up to one Main.py and different modules which are loaded using import and here is also my problem: 1. Main.py executes: 2. Import modules 3. One of the Modules is a SqliteDB datastore. 4. A second module creates an IPC socket. 5. Here is now my problem : The IPC Socket should run a sub which is stored ad SqliteDB and returns all Rows. Is there a elegant way to solve it? except a Queue. Is it possible to import modules multiple?! I'm unsure because the open DB file at another module. How is this solved in bigger projects? Thanks a lot for all answers. BR -- http://mail.python.org/mailman/listinfo/python-list