admin管理员组文章数量:1410682
import inspect
def method():
return "Hello"
source_code = inspect.getsource(method)
print(source_code)
works in both jupyter notebook and .py file
import inspect
class MyClass:
def method(self):
return "Hello"
source_code = inspect.getsource(MyClass)
print(source_code)
works in .py file but in jupyter it's OSError: source code not available
.
What's going on?
Can I understand it is py scripts can inspect all code? What else can or cannot be inspected in jupyter?
Why does this answer () say it errors in interactive shell but both my function and that function works for me in both jupyter and ipython? (my python is 3.10.15, that one is 3.10.6)
本文标签: pythonWhy inspectgetsource only works for functions and not classes in jupyterStack Overflow
版权声明:本文标题:python - Why inspect.getsource only works for functions and not classes in jupyter? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744936010a2633190.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论