使用map调用__init__函数

mot*_*m79 2 python constructor

我想通过调用列表中__init__的每个元素来构造参数列表中的对象列表.有可能吗?这是一个例子:

class Foo(object):
    def __init__(self,x ):
        self.x = x

X = [1,2,3]

ob1 = [Foo(x) for x in X]
# works!

ob2 = map(Foo.__init__, X)
does not work
Run Code Online (Sandbox Code Playgroud)

Dan*_*man 5

没理由说明__init__; 从未明确调用过.只要map(Foo, X)是好的.