Python 按行读取文件

import re

def read_file_text():
s = []
f = open('yingyu.txt', 'r')
for lines in f:
ls = lines.strip(' ').replace(' ', '').replace('\n', '').replace('?', '').split('/')
for inx,val in enumerate(ls):
s.append(val)
print(s)
f.close()

Press the green button in the gutter to run the script.

if name == 'main':
read_file_text()

你可能感兴趣的:(Python 按行读取文件)