继承:

  1. # Dataset 为父类
  2. class COVID19Dataset(Dataset):
  3. pass

构造方法:__init__(self)
长度:__len__
取值:__getitem__

文件

打开文件:with open 可以自动关闭

  1. # 写文件
  2. with open("test.txt", "wt") as out_file:
  3. out_file.write("该文本会写入到文件中\n看到我了吧!")
  4. # Read a file
  5. with open("test.txt", "rt") as in_file:
  6. text = in_file.read()
  7. print(text)