filename='giogio.txt'
word_count=0
with open(filename, encoding='utf8') as f:
contents = f.readlines()
for c in contents:
c = c.strip()
#print(len(c))
word_count+=len(c)
print(f'{word_count} words in all')
参考链接:使用python统计txt文件字数
本文创建于2021年 10月 08日 星期五 19:31:19 CST,修改于2021年 10月 08日 星期五 19:31:19 CST