有没有办法绕过python中的类的构造函数__init__?
例:
class A(object):
def __init__(self):
print "FAILURE"
def Print(self):
print "YEHAA"
现在我想创建一个实例A.它可能看起来像这样,但是这种语法是不正确的。
a = A
a.Print()
Thx提前为您的帮助。
编辑:
一个更复杂的例子:
假设我有一个对象C,它的目的是存储一个单一的参数,并做一些计算。然而,该参数不是这样传递的,而是嵌入在巨大的参数文件中。它可能看起来像这样:
class C(object):
def __init__(self, ParameterFile):
self._Parameter = self._ExtractParamterFile(ParameterFile)
def _ExtractParamterFile(self, ParameterFile):
#does some complex magic to extract the right parameter
return the_extracted_parameter
现在我想转储和加载该对象的实例C.但是,当我加载这个对象,我只有单个变量self._Parameter,我不能调用构造函数,因为它期待参数文件。
@staticmethod
def Load(file):
f = open(file, "rb")
oldObject = pickle.load(f)</