Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspect.getsource raise error OSError: could not get source code #33

Closed
zhqu1148980644 opened this issue Mar 22, 2021 · 2 comments
Closed

Comments

@zhqu1148980644
Copy link

zhqu1148980644 commented Mar 22, 2021

If it's possible to get the source code of the imported class/function

@zhqu1148980644
Copy link
Author

@operatorequals any ideas?

@operatorequals
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants