Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38324

Re: best way to share an instance of a class among modules?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cursor': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'namespace': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'subject:modules': 0.09; 'class)': 0.16; 'created.': 0.16; "module's": 0.16; 'namespace.': 0.16; 'namespace?': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'wrote:': 0.17; 'pointed': 0.17; 'module': 0.19; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; '----': 0.27; 'class': 0.29; 'keyword': 0.30; 'function': 0.30; 'instead,': 0.33; 'like:': 0.33; 'to:addr :python-list': 0.33; 'pm,': 0.35; 'subject:?': 0.35; 'something': 0.35; 'michael': 0.36; 'but': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'remove': 0.61; 'skip:n 10': 0.63; 'within': 0.64; 'received:67.18': 0.65; 'furman': 0.84; 'needed:': 0.84; 'ethan': 0.91
Date Wed, 06 Feb 2013 17:36:28 -0800
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: best way to share an instance of a class among modules?
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>
In-Reply-To <5112FC02.1030805@stoneleaf.us>
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist yes
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender ([173.12.184.235]) [173.12.184.235]:49775
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
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>
Newsgroups comp.lang.python
Message-ID <mailman.1436.1360202172.2939.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360202172 news.xs4all.nl 6853 [2001:888:2000:d::a6]:52534
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38324

Show key headers only | View raw


On 02/06/2013 04:57 PM, Ethan Furman wrote:
> On 02/06/2013 04:43 PM, c wrote:
>> But the function in the module is also within a *class* so I don't
>> think the function does have access to the module's global namespace.
>> Here's the hierarchy:
>>
>> -- Module namespace....
>>      ---- class namespace (DatabaseAccess is the name of the class)
>>           ---- function namespace
>>                This is where the cursor is created.  How do I get it
>> into the module namespace?
>
> In the class namespace you have something like:
>
>          self.shared_cursor = ...
>
> to get that into the module namespace instead, just remove the 'self':
>
>          shared_cursor = ...

Correction:

As Michael Torrie pointed out, the 'global' keyword is needed:

            global shared_cursor
            shared_cursor = ...

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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