我有一个python类。我需要通过为属性传递键/值对或通过将在内部解析的编码字符串来创建实例。使用键/值或字符串初始化类实例
这可能吗?
更新
让我澄清一下。
class Foo(object):
def __init__(self, **kwargs):
# This will let me use key/value arguments
def __init__(self, data):
# This will let me use the whole data as a string
我想结合这两个。
我知道,我可以只有一个参数,可以是dict
或str
,但我不能使用关键字参数。
什么样的班级?什么样的键/值对?这可能是可能的,取决于很多因素...... – zwer