You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here are a few example that show how this fails: In [1]: !ls test_main/ __init__.py __main__.py
In [2]: import test_main ran __init__.py
In [3]: %run test_main ERROR:root:File 'test_main.py' not found.
Using the -m switch seems to work however, the one does not get access to the module namespace like you would when running a regular script. I.e the variable above remains undefined, which is undesirable for interactive work. In [4]: %run -m test_main ran __main__.py
In [4]: variable
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-5-1748287bc46a> in <module>
----> 1 variable
NameError: name 'variable' is not defined
To get access to the namespace one has to provide the full path. %run test_main/__main__.py ran __main__.py In [9]: variable Out[9]: 1
Wondering if it would be possible to get the __main__.py script to run when calling the %run on the module path?
The text was updated successfully, but these errors were encountered:
Here's a small demo package:
With
__init__.py
having one line of code:and
__main__.py
:Here are a few example that show how this fails:
In [1]: !ls test_main/
__init__.py __main__.py
In [2]: import test_main
ran __init__.py
In [3]: %run test_main
ERROR:root:File
'test_main.py'not found.
Using the -m switch seems to work however, the one does not get access to the module namespace like you would when running a regular script. I.e the
variable
above remains undefined, which is undesirable for interactive work.In [4]: %run -m test_main
ran __main__.py
In [4]: variable
To get access to the namespace one has to provide the full path.
%run test_main/__main__.py
ran __main__.py
In [9]: variable
Out[9]: 1
Wondering if it would be possible to get the
__main__.py
script to run when calling the%run
on the module path?The text was updated successfully, but these errors were encountered: