search

Home  >  Q&A  >  body text

Equivalent writing of code.co_kwonlyargcount in Python2

Suppose there is such a piece of code:

>>> def add (x,y):
...     return x + y
... 
>>> c = add.__code__

For Python3, we can get the keyword parameter to be 0 through c.co_kwonlyargcount. For Python2, how to implement equivalent writing and get the corresponding keyword parameter? quantity.

天蓬老师天蓬老师2739 days ago659

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-24 11:37:02

    https://docs.python.org/2/lib...

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-24 11:37:02

    The number of parameters obtained by python2 and python3 is different:

    def add(x, y):
        return x + y
        
    python2:
    c = add.func_code
    c.co_argcount
    
    python3:
    c = add.__code__
    c.co_argcount

    reply
    0
  • Cancelreply