def ReadTxtName1(rootdir):
lines = []
with open(rootdir, 'r') as file_to_read:
while True:
line = file_to_read.readline()
if not line:
break
line = line.strip() #去掉每行头尾空白
line = line.strip('\n')
lines.append(line)
return lines
if __name__ == '__main__':
resultpath = r'新建文本文档.txt'
b = ReadTxtName1(resultpath)
print("b = ",b ,type(b))
运行结果:
运行结果