inspect.getsource raise error OSError: could not get source code
zhqu1148980644 opened this issue · 2 comments
zhqu1148980644 commented
If it's possible to get the source code of the imported class/function
zhqu1148980644 commented
@operatorequals any ideas?
operatorequals commented
The answer is no AFAIK.
Yet, the code is available through HTTP and in fact this is how it got imported!
So checking the location from the class/module object can show as where it is available
From the README.md
>>> import httpimport
>>> pack1 = httpimport.load('test_package','http://localhost:8000/')
>>> pack1
<module 'test_package' from 'http://localhost:8000//test_package/__init__.py'>
You can use requests
or urllib
to fetch http://localhost:8000//test_package/__init__.py
in this example and get the code!