How can I get the source code of a Python function?

后端 未结 12 2000
情话喂你
情话喂你 2020-11-22 02:39

Suppose I have a Python function as defined below:

def foo(arg1,arg2):
    #do something with args
    a = arg1 + arg2
    return a

I can g

12条回答
  •  一向
    一向 (楼主)
    2020-11-22 03:02

    If you are using IPython, then you need to type "foo??"

    In [19]: foo??
    Signature: foo(arg1, arg2)
    Source:
    def foo(arg1,arg2):
        #do something with args
        a = arg1 + arg2
        return a
    
    File:      ~/Desktop/
    Type:      function
    

提交回复
热议问题