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


Groups > comp.lang.python > #38318

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <torriem@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cursor': 0.09; 'imported': 0.09; 'namespace': 0.09; 'subject:modules': 0.09; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; "function's": 0.16; "module's": 0.16; 'namespace.': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'two,': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'module,': 0.17; "shouldn't": 0.17; 'module': 0.19; 'import': 0.21; 'sorry,': 0.22; 'visible': 0.22; 'work.': 0.23; 'this:': 0.23; 'pass': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'question': 0.27; 'module.': 0.27; 'no,': 0.29; "i'm": 0.29; 'function': 0.30; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'self': 0.34; 'problem,': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:org': 0.36; 'skip:u 20': 0.36; 'message-id:@gmail.com': 0.36; 'thank': 0.36; 'enough': 0.36; 'subject:: ': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'little': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'you.': 0.61; 'first': 0.61; 'more': 0.63; 'within': 0.64; 'here': 0.65; 'umm': 0.84
X-Virus-Scanned amavisd-new at torriefamily.org
Date Wed, 06 Feb 2013 17:03:20 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12
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>
In-Reply-To <5db4add7-ab9c-4311-b3b6-24156cd6f248@z4g2000vbz.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
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 <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.1432.1360195406.2939.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360195406 news.xs4all.nl 6886 [2001:888:2000:d::a6]:53651
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38318

Show key headers only | View raw


On 02/06/2013 03:41 PM, CM wrote:
> Thank you.  But, I'm sorry, I'm not following this enough to get it to
> work.  Shouldn't it be a little more like this:

No, not exactly.

> 
> # in utilities module
> shared_cursor =  DatabaseAccess_instance  #but how? see my question
> below...

How what?

> # in importer
> import utilities
> self.shared_cursor = utilities.shared_cursor  ("self" is here to make
> cursor available to all functions in importer

Umm no.  For one you're using self incorrectly.  For two, it already is
visible to all functions in the module.  You just have to refer to it as
"utilities.shared_cursor."

> My only problem, then, is I create the shared_cursor from within a
> function within the instance of DatabaseAccess().  How then do I pass
> it from within the function's namespace to the module's namespace so
> that I can do that first line?

Every function in a module has access to the module's global namespace.
 And your shared_cursor is there, inside of the utilities reference,
since utilities was imported into your module, "importer."

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