问题描述
我有以下设置:
from typing import List
a = List[int]
foo(a) == int
我可以用什么foo
从int
中获取List
?
解决方法
您可以使用属性 __args__
来去掉 int
。
from typing import List
a = List[int]
print(a.__args__[0])
结果:<class 'int'>
我有以下设置:
from typing import List
a = List[int]
foo(a) == int
我可以用什么foo
从int
中获取List
?
您可以使用属性 __args__
来去掉 int
。
from typing import List
a = List[int]
print(a.__args__[0])
结果:<class 'int'>