Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78286
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: import reloading |
| Date | 2014-09-24 09:58 -0400 |
| Organization | news.gmane.org |
| References | <54229482.6040104@chamonix.reportlab.co.uk> <lvub9u$470$1@ger.gmane.org> <5422C866.8010506@chamonix.reportlab.co.uk> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14313.1411566979.18130.python-list@python.org> (permalink) |
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
Re: import reloading Dave Angel <davea@davea.name> - 2014-09-24 09:58 -0400
csiph-web