4

I have a module folder organised as follow:

Hello\
    __init__.py
    world.py

The __ init __.py file contains:

from . import world

and the world.py

def world():
    print('Hello world!')

In a IPython console I can then do

In [1]: import Hello

In [2]: Hello.world.world()
Hello world!

However if I add a new function to world.py this is NOT reloaded by the IPython console. Moreover, if I add a module to Hello\ this is not loaded either, also adding the "from . import world2" to __ init __.py .

Not only! If I modify the function world in the world.py file, this is not reloaded either!

I tried to solve the problem with %autoreload obviously, but this does not seams to work inside modules.

Am I missing a piece of the puzzle? Do I have to open a new console every time I update a module? Should I develop the module "from the inside"?

I looked at this question, but it seams to suggest that %autoreload 2 should work, while it is not for me. Moreover also the other solution

reload(Hello)

does not works and returns

NameError: name 'reload' is not defined
Luca
  • 1,610
  • 1
  • 19
  • 30
  • Can you try `%autoreload` after removing `from . import world` from your `__init__.py`? I suspect your `__init__.py` is telling IPython to import only the `world` function and not others?? The `__init__.py` need not have any content if all you want to do is to declare a folder as a module. –  May 20 '18 at 00:42
  • (*Spyder maintainer here*) I tried your example and it's working fine for me (at least on Linux). The only thing I did is to evaluate something in the console (e.g. `1+1`) before IPython reloaded the module with my new changes. – Carlos Cordoba May 22 '18 at 08:01
  • Apparently after a reboot of the whole system I cannot reproduce the error anymore either. I didn't understand what triggered it, but not being able to reproduce it, I'm afraid I cannot investigate it any further. The strange part is that I used the same exact script to test it, but the behaviour changed... I'll come again here if it happens again – Luca May 24 '18 at 10:32

0 Answers0