Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86270
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.027 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; '(at': 0.04; 'class,': 0.07; 'patterns.': 0.07; 'wrong,': 0.09; "wouldn't": 0.14; '#ifdef': 0.16; 'behavior:': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'simple.': 0.16; 'subject:between': 0.16; 'subject:object': 0.16; 'wrote:': 0.18; 'module': 0.19; 'basically': 0.19; 'import': 0.22; 'header:User- Agent:1': 0.23; 'module,': 0.24; 'tells': 0.24; 'header': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'generally': 0.29; 'especially': 0.30; "i'm": 0.30; 'included': 0.31; 'code': 0.31; 'though.': 0.31; 'up.': 0.33; 'plain': 0.33; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'really': 0.36; 'module.': 0.36; 'processed': 0.36; 'too': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'pm,': 0.38; 'expect': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'up,': 0.60; 'matter': 0.61; 'course': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'times': 0.62; 'email addr:gmail.com': 0.63; 'charset:windows-1252': 0.65; 'hang': 0.67; 'behavior': 0.77; 'subject:Best': 0.91 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Mon, 23 Feb 2015 14:10:07 -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> <mailman.19095.1424717125.18130.python-list@python.org> <ac52606e-f85f-4e94-8dac-6556e28821be@googlegroups.com> |
| In-Reply-To | <ac52606e-f85f-4e94-8dac-6556e28821be@googlegroups.com> |
| 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.19102.1424725814.18130.python-list@python.org> (permalink) |
| Lines | 19 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1424725814 news.xs4all.nl 2862 [2001:888:2000:d::a6]:35270 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86270 |
Show key headers only | View raw
On 02/23/2015 01:02 PM, sohcahtoa82@gmail.com wrote: > That behavior always trips me up. My intuition tells me that every > time you import a module, it re-runs the code in the module. So if I > had a simple module named myModule.py that had a single line with > `myInt = 1`, then I would *EXPECT* this behavior: Basically your intuition is wrong, but I'm not really sure why you think this in the first place, especially if you're familiar with design patterns. A module is a singleton. Plain and simple. If you expect a module to reinstantiate something every time you import it, then what you want is a class, not a module. Even if you think of modules like C header files, as far as use goes, you wouldn't be too far wrong. Generally speaking header files are processed only once no matter how many times they are included (at least the common ones with #ifdef fences in them). I can see how coming from PHP would trip you up, though. Of course I never got the hang of include vs include_once vs require vs require_once.
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