You're passing only one argument to President()
, which is the list
['FDR', False, 4, 1933]
If you want to pass the items in that list as separate arguments, you do it like this:
apresident = President(*testdata) # note the * character
As Colonel Panic points out, in your example the use of argument-unpacking is a little pointless - presumably your actual use case is more complex, and justifies its use.
UPDATE:
Your comment is really a follow-up question which would be better as a separate question, but:
def main():
testdata = {
"president": "FDR",
"alive": False,
"terms": 4,
"firstelected": 1933,
}
apresident = President(**testdata)
anotherpresident = President(president="BHO", terms=2, firstelected=2008)
print apresident
print apresident.alive
print anotherpresident
print anotherpresident.alive
class President:
id_iter = itertools.count(1)
#def __init__(self, president, alive, terms, firstelected):
def __init__(self, **kwargs):
self.id = self.id_iter.next()
self.president = kwargs.get("president", None)
self.alive = kwargs.get("alive", True)
self.terms = kwargs.get("president", 1)
self.firstelected = kwargs.get("president", None)
This shows how you can define default values as well.