Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86254
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torriem+gmail@torriefamily.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.024 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'patterns': 0.04; 'executes': 0.09; 'imported': 0.09; 'variables.': 0.09; 'python': 0.11; 'creates': 0.14; 'attribute.': 0.16; 'constructor.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'instantiated': 0.16; 'modules,': 0.16; 'once.': 0.16; 'subject:between': 0.16; 'subject:object': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'module': 0.19; 'header:User-Agent:1': 0.23; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'program,': 0.31; 'code': 0.31; 'that.': 0.31; 'go.': 0.31; 'class': 0.32; 'stuff': 0.32; 'projects.': 0.33; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'really': 0.36; 'module.': 0.36; 'object,': 0.36; 'level': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'rather': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'solve': 0.60; 'matter': 0.61; 'first': 0.61; 'times': 0.62; 'different': 0.65; 'charset:windows-1252': 0.65; 'between': 0.67; 'special': 0.74; 'dealt': 0.91; 'subject:Best': 0.91; 'state.': 0.95 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Mon, 23 Feb 2015 11:36:05 -0700 |
| From | Michael Torrie <torriem@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Best practice: Sharing object between different objects |
| References | <aacac55a-6779-4ad3-96f4-5332ff36a365@googlegroups.com> <mcfqeb$5tb$1@dont-email.me> |
| In-Reply-To | <mcfqeb$5tb$1@dont-email.me> |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 7bit |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19095.1424717125.18130.python-list@python.org> (permalink) |
| Lines | 22 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1424717125 news.xs4all.nl 2880 [2001:888:2000:d::a6]:46490 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86254 |
Show key headers only | View raw
On 02/23/2015 11:10 AM, Rob Gaddi wrote: > So I'd solve it with module level global variables. It's semi-frowned > upon on software stuff because it creates an unintentional shared state > between different modules, but you really HAVE a shared state, so it > needs to be dealt with. I would also do it with a module attribute. In my mind that's exactly the right way to go. But I disagree that it's frowned on or a bad thing. A module is a completely appropriate place to store state. In fact a module is an object, but a special one that can only be instantiated once. So as far as patterns go, a module is a singleton. Almost any time in Python you have something that you want to have exactly one instance of in your program, you don't want to define a class but rather just use a module. Any code in a module can be considered the constructor. It executes only once in your program when the module is first imported, no matter how many times its imported after that. I often use a module to store configuration that is shared across modules in my projects.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Best practice: Sharing object between different objects pfranken85@gmail.com - 2015-02-21 04:15 -0800
Re: Best practice: Sharing object between different objects Dave Angel <davea@davea.name> - 2015-02-21 09:28 -0500
Re: Best practice: Sharing object between different objects Paul Rubin <no.email@nospam.invalid> - 2015-02-21 09:18 -0800
Re: Best practice: Sharing object between different objects Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-02-23 18:10 +0000
Re: Best practice: Sharing object between different objects Michael Torrie <torriem@gmail.com> - 2015-02-23 11:36 -0700
Re: Best practice: Sharing object between different objects sohcahtoa82@gmail.com - 2015-02-23 12:02 -0800
Re: Best practice: Sharing object between different objects Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-23 20:13 +0000
Re: Best practice: Sharing object between different objects Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-23 13:39 -0700
Re: Best practice: Sharing object between different objects Michael Torrie <torriem@gmail.com> - 2015-02-23 14:10 -0700
Re: Best practice: Sharing object between different objects Chris Angelico <rosuav@gmail.com> - 2015-02-24 11:14 +1100
csiph-web