0

I want to show my ndarray variables "workspace" when there is an exception, so I did the following code :

import sys
import numpy as np
try :
    a1 = np.random.random_integers(5, size=(3,2))
    functionThatProvokesAnException(*arguments)
except Exception as why :
    print("=> ERROR: %s" % why,file=sys.stderr)
    from IPython import get_ipython
    ipython = get_ipython()
    ipython.magic("whos ndarray")
    sys.exit(-2)

But it says : AttributeError: 'NoneType' object has no attribute 'magic'

Can you help ?

SebMa
  • 4,037
  • 29
  • 39
  • 1
    Possible duplicate of [NameError: name 'get\_ipython' is not defined](https://stackoverflow.com/questions/32538758/nameerror-name-get-ipython-is-not-defined) – jordanm Jul 10 '17 at 13:20
  • @jordanm In other words, I guess it's IMPOSSIBLE to run it like this : `python myscript.py` to call ipython magics, am I understanding right ? – SebMa Jul 10 '17 at 13:34
  • That's my understanding, yes – jordanm Jul 10 '17 at 13:40
  • @jordanm Now, how can I test (inside my script) if my scipt has been launched by `ipython` instead of `python` ? – SebMa Jul 10 '17 at 13:52

0 Answers0