In Javascript it would be:
var newObject = { 'propertyName' : 'propertyValue' }; newObject.propertyName; // returns "propertyValue"
But the same syntax in Python would create a dictionary, and that's not what I want
new_object = {'propertyName': 'propertyValue'} new_object.propertyName # raises an AttributeError
Inline objects are embedded in the text flow. If you type more text above them, they are pushed along as the text grows. The selection handles on the top and left side of inline objects are inactive. You cannot drag these handles to resize the object; you can only resize it by dragging the active handles.
We already know that an object is a container of some data and methods that operate on that data. In Python, an object is created from a class. To create an object, you have to define a class first.
obj = type('obj', (object,), {'propertyName' : 'propertyValue'})
there are two kinds of type
function uses.
Python 3.3 added the SimpleNamespace
class for that exact purpose:
>>> from types import SimpleNamespace >>> obj = SimpleNamespace(propertyName='propertyValue') >>> obj namespace(propertyName='propertyValue') >>> obj.propertyName 'propertyValue'
In addition to the appropriate constructor to build the object, SimpleNamespace
defines __repr__
and __eq__
(documented in 3.4) to behave as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With