It's somewhat common knowledge that Python functions can have a maximum of 256 arguments. What I'm curious to know is if this limit applies to *args and **kwargs when they're unrolled in the following manner:
items = [1,2,3,4,5,6]
def do_something(*items):
pass
I ask because, hypothetically, there might be cases where a list larger than 256 items gets unrolled as a set of *args or **kwargs.
解决方案
WFM
>>> fstr = 'def f(%s): pass'%(', '.join(['arg%d'%i for i in range(5000)]))
>>> exec(fstr)
>>> f
Update: as Brian noticed, the limit is on the calling side:
>>> exec 'f(' + ','.join(str(i) for i in range(5000)) + ')'
Traceback (most recent call last):
File "", line 1, in
exec 'f(' + ','.join(str(i) for i in range(5000)) + ')'
File "", line 1
SyntaxError: more than 255 arguments (, line 1)
on the other hand this works:
>>> f(*range(5000))
>>>
Conclusion: no, it does not apply to unrolled arguments.