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


Groups > comp.lang.python > #78286

Re: import reloading

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'session.': 0.07; 'variables': 0.07; 'attributes': 0.09; 'imported': 0.09; 'occasionally': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'bug': 0.12; 'wrote': 0.14; 'anyway': 0.14; "wouldn't": 0.14; 'exist.': 0.16; "module's": 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'subject:import': 0.16; 'weird.': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'reset': 0.22; 'typical': 0.24; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'skip:( 20': 0.30; 'code': 0.31; 'object.': 0.31; 'talked': 0.31; 'there.': 0.32; 'supposed': 0.32; 'run': 0.32; 'skip:# 10': 0.33; 'created': 0.35; 'etc': 0.35; 'test': 0.35; 'instances': 0.36; 'skip:> 10': 0.36; 'useful': 0.36; 'to:addr :python-list': 0.38; 'fact': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'read': 0.60; 'dave': 0.60; 'simply': 0.61; 'save': 0.62; 'times': 0.62; 'more': 0.64; 'mar': 0.68; '2014,': 0.84; 'dozens': 0.84; 'hte': 0.84; 'imp': 0.84; 'presumably': 0.84; 'angel': 0.91; 'hand,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: import reloading
Date Wed, 24 Sep 2014 09:58:13 -0400 (EDT)
Organization news.gmane.org
References <54229482.6040104@chamonix.reportlab.co.uk> <lvub9u$470$1@ger.gmane.org> <5422C866.8010506@chamonix.reportlab.co.uk>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 97.73.240.19
X-Newsreader PiaoHong.Usenet.Client.VIP:1.62
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.14313.1411566979.18130.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1411566979 news.xs4all.nl 2864 [2001:888:2000:d::a6]:47532
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78286

Show key headers only | View raw


Robin Becker <robin@reportlab.com> Wrote in message:
> On 24/09/2014 12:54, Dave Angel wrote:
>> Robin Becker <robin@reportlab.com> Wrote in message:
>>...........
>>> Is a loader supposed to reset all the reused module's attributes and reset the
>>> __dict__ or does it just run the code from the module in hte __dict__?
>>>
>>
>> Nothing gets reset or run. It simply reuses the existing module object.
>>
> I find that a bit weird. In fact as a test I created a testmod.py
> 
> #######
> A=3
> print('A=%r' % A)
> #######
> 
> then in python3.4
> 
> Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit 
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import testmod
> A=3
>  >>> testmod.A
> 3
>  >>> #I externally changed testmod.py to read
>  >>> #a=4
>  >>> #print('a=%r' % a)
>  >>> import imp
>  >>> imp.reload(testmod)
> a=4
> <module 'testmod' from 'C:\\code\\tests\\testmod.py'>
>  >>> testmod.A
> 3
>  >>> testmod.a
> 4
>  >>>
> 
> 
> so you are right the old module variables are still there. Presumably any 
> functions/classes etc etc that don't get overwritten will also continue to exist.
> 
> 


Please don't misquote me. I have no idea why testmod.A gave you a
 number at all.  Must be a bug in reload. Anyway I talked only
 about import. imp.reload is an abomination useful only to
 occasionally save time in an interactive session.
 

import, on the other hand, had better continue to be consistent. 
 Many modules are imported dozens of times in a typical
 application,  and you wouldn't want multiple instances of
 them.

-- 
DaveA

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


Thread

Re: import reloading Dave Angel <davea@davea.name> - 2014-09-24 09:58 -0400

csiph-web