Sac*_*try 3 c# python class instantiation
我想知道是否有一种快速方法来初始化python中的对象.
例如,在c#中,您可以实例化一个对象并设置字段/属性,如...
SomeClass myObject = new SomeClass() { variableX = "value", variableY = 120 };
谢谢
布赖恩
如果你想要一个带有一些字段的快速脏对象,我强烈建议使用namedtuples
from collections import namedtuple
SomeClass = namedtuple('Name of class', ['variableX', 'variableY'], verbose=True)
myObject = SomeClass("value", 120)
print myObject.variableX