Skip to content

Instantly share code, notes, and snippets.

@ars096
Last active June 14, 2019 04:47
Show Gist options
  • Save ars096/41bc142589f7aecf188463930e28ccc2 to your computer and use it in GitHub Desktop.
Save ars096/41bc142589f7aecf188463930e28ccc2 to your computer and use it in GitHub Desktop.
How to notice a module imported from ipython-env
$ ipython
In [1]: import inspect
...:
...: for s in inspect.stack():
...: m = inspect.getmodule(s[0])
...: if m: print(m.__file__)
...:
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/core/interactiveshell.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/core/interactiveshell.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/core/interactiveshell.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/core/async_helpers.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/core/interactiveshell.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/core/interactiveshell.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/terminal/ipapp.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/traitlets/config/application.py
/Users/nishimura/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/IPython/__init__.py
$ python test1.py
-- test1
test1.py
$ python test2.py
-- test1
/Users/nishimura/python/misc/20190614-import-test/test1.py
test2.py
-- test2
test2.py
$ python test3.py
-- test1
/Users/nishimura/python/misc/20190614-import-test/test1.py
/Users/nishimura/python/misc/20190614-import-test/test2.py
test3.py
-- test2
/Users/nishimura/python/misc/20190614-import-test/test2.py
test3.py
print('-- test1')
import inspect
for s in inspect.stack():
m = inspect.getmodule(s[0])
if m: print(m.__file__)
import test1
print('-- test2')
import inspect
for s in inspect.stack():
m = inspect.getmodule(s[0])
if m: print(m.__file__)
import test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment