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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744936010a4602028.html
评论列表(0条)