Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'subsequent': 0.04; 'subject:Python': 0.05; 'cache': 0.05; 'socket': 0.05; '"__main__":': 0.07; '%s"': 0.07; '__name__': 0.07; 'elegant': 0.07; 'executed': 0.07; 'predefined': 0.07; 'problem:': 0.07; 'subject:help': 0.07; 'python': 0.09; 'cursor': 0.09; 'imports': 0.09; 'sqlite': 0.09; 'sub': 0.09; 'subject:2.7': 0.09; 'to:addr:comp.lang.python': 0.09; 'valueerror': 0.09; 'cc:addr:python-list': 0.10; 'stored': 0.10; 'subject:Help': 0.10; 'def': 0.10; '(everything': 0.16; ':-p': 0.16; 'larger,': 0.16; 'overview:': 0.16; 'row': 0.16; 'samstag,': 0.16; 'scopes': 0.16; 'socket.': 0.16; 'subject:] [': 0.16; 'tcp': 0.16; 'threads': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'yield': 0.17; 'creates': 0.18; 'code,': 0.18; 'subject:] ': 0.19; 'module': 0.19; 'written': 0.20; 'all,': 0.21; 'bit': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'flexibility': 0.23; 'split': 0.23; 'raise': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'device': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'updating': 0.27; 'functions.': 0.27; 'instead.': 0.27; 'module.': 0.27; 'run': 0.28; "i'm": 0.29; 'connection': 0.30; 'projects.': 0.30; 'function': 0.30; 'code': 0.31; 'point': 0.31; 'file': 0.32; 'running': 0.32; 'correctly.': 0.33; 'that!': 0.33; 'problem': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'project': 0.34; 'thanks': 0.34; 'whatever': 0.35; 'bigger': 0.35; 'from:addr:googlemail.com': 0.35; 'open': 0.35; 'table': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'except': 0.36; 'serve': 0.36; 'but': 0.36; 'loaded': 0.36; 'modules': 0.36; 'anything': 0.36; 'should': 0.36; 'problems': 0.36; 'subject: (': 0.36; 'possible': 0.37; 'correctly': 0.37; 'level': 0.37; 'received:209': 0.37; 'data': 0.37; 'object': 0.38; 'takes': 0.39; 'hello,': 0.39; 'skip:" 10': 0.40; 'think': 0.40; 'from:no real name:2**0': 0.60; 'skip:u 10': 0.60; 'real': 0.61; 'first': 0.61; '!!!': 0.62; 'solve': 0.62; 'different': 0.63; 'more': 0.63; 'here': 0.65; '.....': 0.75; 'informations': 0.75; 'answer:': 0.84; 'lot,': 0.95 Newsgroups: comp.lang.python Date: Sat, 22 Dec 2012 04:38:11 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=81.217.27.214; posting-account=cEKlTgoAAACa82UEsarDnR5Dm6ErawNg References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 81.217.27.214 MIME-Version: 1.0 Subject: Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) From: prilisauer@googlemail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 170 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356179894 news.xs4all.nl 6853 [2001:888:2000:d::a6]:49642 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35358 Am Samstag, 22. Dezember 2012 12:43:54 UTC+1 schrieb Peter Otten: > wrote: >=20 >=20 >=20 > > Hello, to all, >=20 > >=20 >=20 > > I hope I can describe me problem correctly. >=20 > >=20 >=20 > > I have written a Project split up to one Main.py and different modules >=20 > > which are loaded using import and here is also my problem: >=20 > >=20 >=20 > > 1. Main.py executes: >=20 > > 2. Import modules >=20 > > 3. One of the Modules is a SqliteDB datastore. >=20 > > 4. A second module creates an IPC socket. >=20 > > 5. Here is now my problem : >=20 > > The IPC Socket should run a sub which is stored ad SqliteDB and >=20 > > returns all Rows. >=20 > >=20 >=20 > > Is there a elegant way to solve it? except a Queue. Is it possible to >=20 > > import modules multiple?!=20 >=20 >=20 >=20 > If you import a module more than once code on the module level will be=20 >=20 > executed the first time only. Subsequent imports will find the ready-to-u= se=20 >=20 > module object in a cache (sys.modules). >=20 >=20 >=20 > > I'm unsure because the open DB file at another >=20 > > module. >=20 > >=20 >=20 > > How is this solved in bigger projects? >=20 >=20 >=20 > If I'm understanding you correctly you have code on the module level that= =20 >=20 > creates a socket or opens a database. Don't do that! >=20 > Put the code into functions instead. That will give the flexibility you n= eed=20 >=20 > for all sizes of projects. For instance >=20 >=20 >=20 > socket_stuff.py >=20 >=20 >=20 > def send_to_socket(rows): >=20 > socket =3D ... # open socket >=20 > for row in rows: >=20 > # do whatever it takes to serialize the row >=20 > socket.close() >=20 >=20 >=20 > database_stuff.py >=20 >=20 >=20 > def read_table(dbname, tablename): >=20 > if table not in allowed_table_names: >=20 > raise ValueError >=20 > db =3D sqlite3.connect(dbname) >=20 > cursor =3D db.cursor() >=20 > for row in cursor.execute("select * from %s" % tablename): >=20 > yield row >=20 > db.close() >=20 >=20 >=20 >=20 >=20 > main.py >=20 >=20 >=20 > import socket_stuff >=20 > import database_stuff >=20 >=20 >=20 > if __name__ =3D=3D "__main__": >=20 > socket_stuff.send_to_socket( >=20 > 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)=20 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.=20 # Stored Informations should be kept in Datastore # Advanced scheduler I don't know, Python allways looks for me like a one script "File". But the= re are big projects. like the the "Model of an SQL Server", using coordinat= ors no problems running threads and exchange Data through a Backbone. I hav= e 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