I am scratching my head on what is going in the following code.
class foo(object):
def __init__(self,*args):
print type(args)
print args
j_dict = {'rmaNumber':1111, 'caseNo':2222}
print type(j_dict)
p = foo(j_dict)
it yields :
({'rmaNumber': 1111, 'caseNo': 2222},)
It seems to me that this code converts a dict to a tuple!! Can anyone explain this
Answer
Actually it's because args is a tuple to hold a variable length argument list. args[0] is still your dict - no conversion has taken place.
See this tutorial for further information about args and kwargs (the keyword version of args).
No comments:
Post a Comment