简体   繁体   English

在交互式外壳中预览类或函数定义源代码

[英]Previewing the class or function definition source code in the interactive shell

Is it possible to access a source code of the imported class or funciton while using interactive shell like IDLE Shell or Linux python? 使用诸如IDLE Shell或Linux python之类的交互式Shell时是否可以访问导入的类或函数的源代码?

In example, I wish that it was possible to do the following: 例如,我希望可以做到以下几点:

from myClasses import MyClass

#this
print MyClass.__source__ 
#or that
source(MyClasss)

# would result in:
def MyClass(object):
    pass
from myClasses import MyClass
import inspect

source = inspect.getsource(MyClass)
print source

#class MyClass(object):
#    pass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM