.>>> source_text = inspect.getsource(A) File"<stdin>", line 1, in <module>
File "C:\Users\**\Python\Python36\lib\inspect.py", line 968, in getsource</e
我正在尝试使用Python的自省模块inspect来检索活动对象的源代码,这些活动对象已经通过importlib.util的module_from_spec函数加载到作用域中。尝试在spec_file本身或spec文件中的任何函数上使用inspect.getsource()都会成功返回所需的源代码。assert isinstance(inspect.getsource(spec_module), str)
# function in spec mod
我正在尝试使用shelve模块来保存我的会话输出并在以后重新加载它,但是我发现如果我已经定义了函数,那么在重新加载阶段就会出现一个错误。我的做法有问题吗?我的代码是基于的一个答案。print my_shelf['test_fn']AttributeErrorUnpickler(f).load()
123 if self.writeback