[Tutor] Python decorator to ensure that kwargs are correct

Rich Lovely roadierich at googlemail.com
Sat Sep 19 02:02:16 CEST 2009


Should probably clean up my code properly before submitting, to hide
some of the noobish errors like forgetting to put quotes round
strings...

>>> class Demo(object):
... 	def __init__(self, name="", surname="", age=0):
... 		print name, surname, age
... 		
>>> Demo(name='Rich', surname='Lovely', age=24)
Rich Lovely 24
<__main__.Demo object at 0x00F75230>
>>> Demo(notAName='foo')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'notAName'


-- 
Rich "Roadie Rich" Lovely

There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.


More information about the Tutor mailing list