【发布时间】:2020-01-19 05:05:33
【问题描述】:
在运行我的 python3 代码时,我收到以下错误:
'TypeError: 'type' 对象不可下标'
当我尝试将 __init__ class 参数设置为 List[int] 时,系统无法识别具有 List 参数的输入模块
我已经通过pip 安装了typing.py 模块并尝试使用import typing
即使系统无法识别类定义中的List[int] 类型。
下面是相同的代码,
from typing import List
class newcls:
def __init__(self, a: int,arr: list[int]):
self.a=a
self.arr=arr
def new1(self):
print('a=',self.a)
print(self.arr)
obj1=newcls(1,[1,2,3])
obj1.new1()
还有我在运行时收到的错误消息,
运行时错误为 def init(self, a: int,arr: list[int]):
TypeError:'type' 对象不可下标
【问题讨论】:
标签: python-3.x list types importerror