import os
classes_path = os.path.expanduser('./my_Chinese_classes.txt')
with open(classes_path,'r',encoding ='UTF-8') as f:
class_names = f.readlines()
class_names =[c.strip()for c in class_names]print(class_names)
python按行读取txt文件内容并写入列表源码效果图源码import osclasses_path = os.path.expanduser('./my_Chinese_classes.txt')with open(classes_path,'r',encoding = 'UTF-8') as f: class_names = f.readlines()class_names = [c.strip() for c in class_names]print(class_names)效