【发布时间】:2019-04-18 05:41:12
【问题描述】:
我有一个类似于下面给出的课程:
class Someclass(object):
def __init__(self, n1=5, n2=12):
self.n1 = n1
self.n2 = n2
我想在一个函数中使用来自上述类的__init__ 的参数,我以下列方式定义:
def Search(model: Someclass):
n11 = 10
n22 = 20
print( type(model.__init__), type(model) )
# I want to multiply self.n1 with n11 , and self.n2 with n22 using this function.
Search(Someclass)
>> <class 'function'> <class 'type'>
如何在Someclass 内部Search 中访问__init__ 构造函数中的元素?
【问题讨论】: