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


Groups > comp.lang.python > #86263

Re: Best practice: Sharing object between different objects

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'cache': 0.07; 'sys': 0.07; 'referenced': 0.09; '23,': 0.16; 'imported).': 0.16; 'locally,': 0.16; 'subject:between': 0.16; 'subject:object': 0.16; 'sys.modules': 0.16; 'variable.': 0.16; 'wrote:': 0.18; 'module': 0.19; 'feb': 0.22; '>>>': 0.22; 'import': 0.22; 'reset': 0.22; 'mon,': 0.24; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'received:google.com': 0.35; 'really': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'deleting': 0.60; '2015': 0.84; 'subject:Best': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=DR2GyH9hwwifXgFiLpAYSRA2lu8p24D9/85gnPspflQ=; b=FMSeyoFzh3ywUymzk4z1eXTNUHLskm2NLD449pOQuYRN7QCtypHqhQCuuuw2gAbviS 3SsiDTG9oDTCKxRSC8xtMvRkGi6InxqE6eUdQTG5jgIVXeJDP9TUPIHoIygrH9NQRRbr ozJ9EHg72r5dfYk6SnrGSHkZprDtX2MANQHRFLPyQ9XzrfYG4VHfuT4nOfmiu8+rsLI8 KaJj4PmCBZjwkJ9NeF/Qw9hp/HcJ2jOlrC6yBeWUweCQQEm2YKMERTOwl/gBBR7Qjv1I y7a9awP8E/mVuRxXJ39XG9pRS+Y1SFRwGekjEe7C5qhF9vxAdBA7WEe3pntirXcq0Frw AxFg==
X-Received by 10.70.42.177 with SMTP id p17mr21953330pdl.91.1424724032596; Mon, 23 Feb 2015 12:40:32 -0800 (PST)
MIME-Version 1.0
In-Reply-To <ac52606e-f85f-4e94-8dac-6556e28821be@googlegroups.com>
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>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 23 Feb 2015 13:39:52 -0700
Subject Re: Best practice: Sharing object between different objects
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.19100.1424724040.18130.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424724040 news.xs4all.nl 2964 [2001:888:2000:d::a6]:50748
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86263

Show key headers only | View raw


On Mon, Feb 23, 2015 at 1:02 PM,  <sohcahtoa82@gmail.com> wrote:
> What's REALLY interesting is that this happens:
>
>>>> import myModule
>>>> myModule.myInt
> 1
>>>> myModule.myInt = 2
>>>> myModule.myInt
> 2
>>>> del myModule
>>>> import myModule
>>>> myModule.myInt
> 2
>
> I would REALLY expect that deleting the module object and then re-importing would reset that variable.

Even though you deleted the module locally, it's still referenced in
the sys.modules cache (as well as in any other place where it might
have been imported). That's the place you need to delete it from if
you really want to re-execute it.

>>> import myModule
>>> myModule.myInt
1
>>> myModule.myInt = 2
>>> myModule.myInt
2
>>> import sys
>>> del sys.modules['myModule']
>>> import myModule
>>> myModule.myInt
1

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


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