Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38396
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rantingrickjohnson@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'pat': 0.05; 'dependency': 0.07; 'encouraging': 0.07; 'python': 0.09; 'facts': 0.09; 'subject:modules': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'suggest': 0.11; 'language': 0.14; 'constants': 0.16; 'hierarchy': 0.16; 'namespace,': 0.16; 'namespace.': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'variables),': 0.16; 'wrote:': 0.17; 'pointed': 0.17; 'variables': 0.17; 'code,': 0.18; 'module': 0.19; 'variable': 0.20; 'import': 0.21; 'constant': 0.22; 'wednesday,': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'testing': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'module.': 0.27; 'strongly': 0.27; 'lines': 0.28; 'statements': 0.29; 'classes': 0.30; 'keyword': 0.30; 'code': 0.31; 'could': 0.32; 'anyone': 0.33; 'know.': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'needed': 0.35; 'exist': 0.35; 'especially': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'created': 0.36; 'michael': 0.36; 'but': 0.36; 'anything': 0.36; 'does': 0.37; 'level': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'fact': 0.38; 'object': 0.38; 'advice': 0.39; 'little': 0.39; 'skip:" 10': 0.40; 'back': 0.62; 'else.': 0.65; 'subject': 0.66; 'middle': 0.66; 'skip:$ 10': 0.66; 'manner': 0.74; 'yourself': 0.77; '2013': 0.84; 'furman': 0.84; 'needed:': 0.84; 'ethan': 0.91; 'hate': 0.93 |
| X-Received | by 10.49.4.231 with SMTP id n7mr353019qen.34.1360289649715; Thu, 07 Feb 2013 18:14:09 -0800 (PST) |
| Newsgroups | comp.lang.python |
| Date | Thu, 7 Feb 2013 18:14:09 -0800 (PST) |
| In-Reply-To | <mailman.1436.1360202172.2939.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=70.196.110.35; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj |
| References | <15fe7153-a77a-49eb-9cf8-d4e59b4a2079@z9g2000vbx.googlegroups.com> <mailman.1401.1360127082.2939.python-list@python.org> <5db4add7-ab9c-4311-b3b6-24156cd6f248@z4g2000vbz.googlegroups.com> <mailman.1432.1360195406.2939.python-list@python.org> <aa4c4a88-5d14-4875-aa1c-0e611cc0badd@z4g2000vbz.googlegroups.com> <5112FC02.1030805@stoneleaf.us> <mailman.1436.1360202172.2939.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 70.196.110.35 |
| MIME-Version | 1.0 |
| Subject | Re: best way to share an instance of a class among modules? |
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.1469.1360289657.2939.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360289657 news.xs4all.nl 6900 [2001:888:2000:d::a6]:56637 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38396 |
Show key headers only | View raw
On Wednesday, February 6, 2013 7:36:28 PM UTC-6, Ethan Furman wrote: > As Michael Torrie pointed out, the 'global' keyword is needed: Wrong. The global keyword is in fact NOT needed and something i consider to be another wart of the language (PyWart on this subject coming soon!). Now, whilst Micheal's advice is valid python code, i would strongly suggest against encouraging people to use the global keyword when they could simply declare the variable beforehand. I know what you are thinking: """ But python does not /require/ us to declare global variables if we use the global keyword""" Yes, i know. But i just hate to have variables created "magically" in the middle of execution! ESPECIALLY if these variables are going to be accessed from another module(s). *sniff-sniff* does anyone smell what i smell? Listen. I want to know every variable and every CONSTANT that will exist in the module namespace, and i want to know these facts BEFORE i read anything else. So please declare them at the top of each module. Hierarchy of module code structure: 0. shebang lines 1. stdlib import statements 2. 3rd party and dependency import statements 3. CONSTANTS 4. $globalVariables 5. module functions 6. module classes (bka: Object Definitions) 7. Testing Area So if you want to use "global variables" , (bka: Module level variables), then simply declare them with a None value like this: globalVariable = None But don't pat yourself on the back just yet! Place a little comment so the reader will understand that this variable is accessed from ANOTHER namespace. sharedCursor = None # Set by "Class.blah"; Whored out to X,Y and Z! In this manner i will not be blindsided by proper use of poor language features.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
best way to share an instance of a class among modules? CM <cmpython@gmail.com> - 2013-02-05 20:40 -0800
Re: best way to share an instance of a class among modules? Terry Reedy <tjreedy@udel.edu> - 2013-02-06 00:04 -0500
Re: best way to share an instance of a class among modules? CM <cmpython@gmail.com> - 2013-02-06 14:41 -0800
Re: best way to share an instance of a class among modules? Michael Torrie <torriem@gmail.com> - 2013-02-06 17:03 -0700
Re: best way to share an instance of a class among modules? c <chaelon@gmail.com> - 2013-02-06 16:43 -0800
Re: best way to share an instance of a class among modules? Ethan Furman <ethan@stoneleaf.us> - 2013-02-06 16:57 -0800
Re: best way to share an instance of a class among modules? Ethan Furman <ethan@stoneleaf.us> - 2013-02-06 17:36 -0800
Re: best way to share an instance of a class among modules? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-07 18:14 -0800
Re: best way to share an instance of a class among modules? Michael Torrie <torriem@gmail.com> - 2013-02-07 23:05 -0700
Re: best way to share an instance of a class among modules? Michael Torrie <torriem@gmail.com> - 2013-02-08 21:54 -0700
Re: best way to share an instance of a class among modules? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-07 18:14 -0800
Re: best way to share an instance of a class among modules? Michael Torrie <torriem@gmail.com> - 2013-02-06 17:14 -0700
Re: best way to share an instance of a class among modules? CM <cmpython@gmail.com> - 2013-02-06 16:45 -0800
Re: best way to share an instance of a class among modules? Michael Torrie <torriem@gmail.com> - 2013-02-06 18:08 -0700
csiph-web