一、splitlines() 方法
splitlines() 方法将字符串拆分为列表,拆分在换行符处完成。
以行为单位存成列表
txt = "Thank you for the music\nWelcome to the jungle"
x = txt.splitlines()
print(x)
['Thank you for the music', 'Welcome to the jungle']
把文本全读进来,这样才可以对每一行进行拆解
with open(path, "r") as f:
#Python splitlines() 按照行('\r', '\r\n', \n')分隔
labels = f.read().splitlines()
if "O" not in labels:
labels = ["O"] + labels
return labels