How do I write a one-liner for the following?
class MyClass(): content = {}
obj = MyClass()
How do I write a one-liner for the following?
class MyClass(): content = {}
obj = MyClass()
You can use type
as an alternative way to create a class:
MyClass = type('MyClass', (object,), {'content':{}})
obj = MyClass()
or, in one line without binding the class to a name:
obj = type('MyClass', (object,), {'content':{}})()
The first argument being the name, the second the bases and the third the class namespace.