Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35360
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <prilisauer@googlemail.com> |
| 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; 'sockets': 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; 'closes': 0.16; 'interaction,': 0.16; 'larger,': 0.16; 'overview:': 0.16; 'row': 0.16; 'samstag,': 0.16; 'scopes': 0.16; 'situation.': 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; 'socket,': 0.29; "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; 'could': 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; 'server': 0.35; '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; "didn't": 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; 'received:209.85.214': 0.39; '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; 'dead': 0.62; 'solve': 0.62; 'different': 0.63; 'more': 0.63; 'here': 0.65; 'informations': 0.75; 'answer:': 0.84; 'open,': 0.84; 'lot,': 0.95 |
| Newsgroups | comp.lang.python |
| Date | Sat, 22 Dec 2012 04:45:27 -0800 (PST) |
| In-Reply-To | <mailman.1196.1356179894.29569.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=81.217.27.214; posting-account=cEKlTgoAAACa82UEsarDnR5Dm6ErawNg |
| References | <ab077ea4-2cfd-4769-afa7-b0cd0045e2d6@googlegroups.com> <mailman.1194.1356176640.29569.python-list@python.org> <mailman.1196.1356179894.29569.python-list@python.org> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.1197.1356180330.29569.python-list@python.org> (permalink) |
| Lines | 348 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1356180330 news.xs4all.nl 6899 [2001:888:2000:d::a6]:55256 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:35360 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 02:59 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Peter Otten <__peter__@web.de> - 2012-12-22 12:43 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 04:38 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Peter Otten <__peter__@web.de> - 2012-12-22 14:54 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 08:36 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 08:36 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 04:38 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 04:45 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Terry Reedy <tjreedy@udel.edu> - 2012-12-22 16:30 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 04:45 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Alexander Blinne <news@blinne.net> - 2012-12-22 18:26 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 10:10 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Alexander Blinne <news@blinne.net> - 2012-12-22 20:29 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-22 12:43 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Alexander Blinne <news@blinne.net> - 2012-12-22 22:59 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-23 01:32 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Terry Reedy <tjreedy@udel.edu> - 2012-12-23 20:53 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Alexander Blinne <news@blinne.net> - 2012-12-24 14:10 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dave Angel <d@davea.name> - 2012-12-22 17:03 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Cameron Simpson <cs@zip.com.au> - 2012-12-23 21:55 +1100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-23 12:59 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Peter Otten <__peter__@web.de> - 2012-12-23 22:14 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-23 12:59 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Roy Smith <roy@panix.com> - 2012-12-23 16:15 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-23 13:42 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2012-12-23 23:38 +0000
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-24 00:01 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Thomas Bach <thbach@students.uni-mainz.de> - 2012-12-24 06:18 +0100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dave Angel <d@davea.name> - 2012-12-24 00:19 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-24 00:23 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Cameron Simpson <cs@zip.com.au> - 2012-12-24 21:32 +1100
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dave Angel <d@davea.name> - 2012-12-24 10:48 -0500
Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Ranting Rick <rantingrickjohnson@gmail.com> - 2012-12-24 21:10 -0800
Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-25 04:55 -0800
Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-25 16:04 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dave Angel <d@davea.name> - 2012-12-24 11:47 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dave Angel <d@davea.name> - 2012-12-24 18:09 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-24 00:23 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-25 13:44 +0000
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-25 06:41 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dave Angel <d@davea.name> - 2012-12-25 12:10 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-25 09:31 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-25 09:31 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Rick Johnson <rantingrickjohnson@gmail.com> - 2012-12-25 12:16 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-25 16:08 -0500
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Rick Johnson <rantingrickjohnson@gmail.com> - 2012-12-25 15:42 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Michael Torrie <torriem@gmail.com> - 2012-12-26 12:20 -0700
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Michael Torrie <torriem@gmail.com> - 2012-12-26 11:58 -0700
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Rick Johnson <rantingrickjohnson@gmail.com> - 2012-12-25 15:42 -0800
Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) alex23 <wuwei23@gmail.com> - 2012-12-25 19:18 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Rick Johnson <rantingrickjohnson@gmail.com> - 2012-12-25 12:16 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-25 22:56 +0000
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Rick Johnson <rantingrickjohnson@gmail.com> - 2012-12-25 16:19 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-26 08:29 +0000
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Rick Johnson <rantingrickjohnson@gmail.com> - 2012-12-26 20:07 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 05:02 +0000
Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Ranting Rick <rantingrickjohnson@gmail.com> - 2012-12-26 22:50 -0800
Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) Chris Angelico <rosuav@gmail.com> - 2012-12-27 23:58 +1100
Re: Require help migrating from Perl to Python 2.7 (namespaces) alex23 <wuwei23@gmail.com> - 2012-12-27 05:25 -0800
Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces) prilisauer@googlemail.com - 2012-12-23 01:36 -0800
csiph-web