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


Groups > comp.lang.python > #78286 > unrolled thread

Re: import reloading

Started byDave Angel <davea@davea.name>
First post2014-09-24 09:58 -0400
Last post2014-09-24 09:58 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#78286 — Re: import reloading

FromDave Angel <davea@davea.name>
Date2014-09-24 09:58 -0400
SubjectRe: import reloading
Message-ID<mailman.14313.1411566979.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web