Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

create anonymous objects in Python

#So brief, such Python! O.o
>>> Object = lambda **kwargs: type("Object", (), kwargs)

#Then you can use Object as a generic object constructor:
>>> person = Object(name = "Bernhard", gender = "male", age = 42)
>>> person.name
'Bernhard'
>>>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #create #anonymous #objects #Python
ADD COMMENT
Topic
Name
3+2 =