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


Groups > comp.lang.python > #38497

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

Date 2013-02-08 21:54 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: best way to share an instance of a class among modules?
References (3 earlier) <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> <5b81481d-b7ee-40a2-92ba-4bfb174e1694@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1532.1360385670.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 02/07/2013 07:14 PM, Rick Johnson wrote:

> So if you want to use "global variables" , (bka: Module level
> variables), then simply declare them with a None value like this:
> 
> globalVariable = None

This is a nice convention, but at best it's just a helpful notation that
helps a programmer know something useful may likely be bound to this
name in the future.

The '=' sign in Python isn't an assignment operator, at least in this
case; it's a binding operator.  Thus any future line that sets
globalVariable to something isn't assigning a value to this
already-declared variable.  Instead it's binding the name globalValue to
a new object, and overwriting the name in the module dictionary.  That's
of course why the global keyword is required, so that Python will use
the module dictionary instead of the local scope one.

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