pktl2k
pktl2k

Reputation: 650

Python import and reload misunderstanding

The original title was: 'Numpy array: 'data type not understood''. Turns out, the problem was my misunderstanding of Python as an interpreted language.

I have this very simple module 'rtm.py':

import numpy as np
def f():
    A=np.array([[1.0,0.5],[0.0,1.0]])

But when I run it in IPython:

import rtm
rtm.f()

I get this error:

      1 import numpy as np
      2 def f():
----> 3         np.array([[1.0,0.5],[0.0,1.0]])

TypeError: data type not understood

Which part in the documentation didn't I understand?

Thanks in advance!

Upvotes: 1

Views: 1182

Answers (1)

zero323
zero323

Reputation: 330083

If you want to made external changes in modules visible inside interpreter session you have to use reload instead import:

Python 2

import rtm
# some change in rtm.foo has been made
import rtm 
rtm.foo() # Old version of rtm.foo is called

reload(rtm) # You have to reload module ([docs][1])
rtm.foo() # Now you can call new version of rtm.foo

Python 3

...
from imp import reload
reload(rtm)

Upvotes: 1

Related Questions