Here is my code snappt:
class C(dict):
def __init__(*args, **kwds):
print 'args = {}'.format(args)
print 'kwds = {}'.format(kwds)
if not args:
raise TypeError("descriptor '__init__' of 'Counter' object needs an argument")
self = args[0]
args = args[1:]
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
super(C, self).__init__()
if __name__ == '__main__':
c = C()
When i run this code, i am confused with the output:
C:\Users\elqstux\Desktop>python wy.py
args = ({},)
kwds = {}
For c = C()
, i think the code will raise a Error, because args
will be ()
in this case, but from the output, args
is ({},)
, what't the reason?
self, args = args[0], args[1:] # allow the "self" keyword be passed