Are there any shortcuts for defining an empty object in Python or do you always have to create an instance of a custom empty class?
Edit: I mean an empty object usable for duck typing.
|
You can use type to create a new class on the fly and then instantiate it. Like so:
The arguments to type are: Class name, a tuple of base classes, and the object's dictionary. Which can contain functions (the object's methods) or attributes. You can actually shorten the first line to
Because by default type creates new style classes that inherit from object.
But if you just want to create an instance of object. Then, just create an instance of it. Like lejlot suggests. |
||||
|
What do you mean by "empty object"? Instance of class
or maybe you mean initialization to the null reference? Then you can use
|
|||||
|