Python reload, and IPython autoreload as well, is not working -


i using python + ipython data science. made folder contains modules wrote, organised in packages, like

python_workfolder | |---a |   |---__init__.py |   |---a1.py |   |---a2.py | |---b |   |---__init__.py |   |---b1.py |   |---b2.py | |---c |   |---__init__.py |   |---c1.py |   |---c2.py | | |---script1.py |---script2.py 

at beginning of each session ask ipython autoreload modules:

%load_ext autoreload %autoreload 2 

now... let's a1.py contains class, a1, want call 1 of scripts. in __init__.p of package a import module

import a1 

then in script import class need

from a.a1 import a1 

if there error in class a1 , modify it, there no way have python reload without restarting kernel.

i tried del a1, del sys.modules['a1'], del sys.modules['a']. each time uses old version of class until don't restart kernel... can give me suggestions?

this funny. seems problem not due ipython pyzo (the ide i'm using). added testclass a1:

class testclass:     def __init__(self):         pass     def disp(self):         print('aaa') 

this output running commands in ipython shell:

in [2]: a.a1 import testclass in [3]: t=testclass() in [4]: t.disp() aaa 

now modify disp print 'bbb'

in [5]: t.disp() bbb 

so reloaded... because if skip running autoreload commands @ beginning, prints 'aaa' again. it's working.

instead if run commands through pyzo (create script, select lines , press f9 or right click on editor tab , select 'run file') doesn't reloaded!

in [2]: (executing lines 1 3 of "testscript.py") aaa 

again modify disp print 'bbb'

in [3]: (executing lines 1 3 of "testscript.py") aaa 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -