从字典值实例化类的好方法

问题描述 投票:-2回答:1

假设我有这个:

a = {1: __class} 

这个丑陋的片段a[1]()是否有其他选择?

也尝试过a[1].__call__(argument),但PyCharm抱怨Expected type 'type', got X instead

在我看来,它击败了这一说法:

显式优于隐式

python python-3.x dictionary instantiation
1个回答
1
投票

虽然a[1]()没什么问题,但如果您真的想争论说它不够明确...

the_function_that_i_pulled_from_the_dictionary = a[1]
the_function_that_i_pulled_from_the_dictionary()
© www.soinside.com 2019 - 2024. All rights reserved.