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: 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: References: From: Ian Kelly Date: Mon, 23 Feb 2015 13:39:52 -0700 Subject: Re: Best practice: Sharing object between different objects To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Mon, Feb 23, 2015 at 1:02 PM, 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