How to create inline objects with properties?

后端 未结 9 702
误落风尘
误落风尘 2020-12-04 19:12

In Javascript it would be:

var newObject = { \'propertyName\' : \'propertyValue\' };
newObject.propertyName;  // retur         


        
9条回答
  •  自闭症患者
    2020-12-04 19:44

    I don't know if there's a built-in way to do it, but you can always define a class like this:

    class InlineClass(object):
        def __init__(self, dict):
            self.__dict__ = dict
    
    obj = InlineClass({'propertyName' : 'propertyValue'})
    

提交回复
热议问题