from itertools import chain
from glob import glob
file = open('FortInventory.txt','w')
lines = [line.lower() for line in lines]
with open('FortInventory.txt', 'w') as out:
out.writelines(sorted(lines))
我正在尝试将txt文件中的所有文本都转换为小写字母,我将如何执行此操作,这是我到目前为止的代码,我看了一些关于堆栈溢出的问题,但是我想不通,如果有人可以链接正确的文章,或者告诉我我的代码有什么问题,我将不胜感激。
两个问题:
'r'
进行读取。lines
为file
列表理解中的。这是固定代码:
from itertools import chain
from glob import glob
file = open('FortInventory.txt', 'r')
lines = [line.lower() for line in file]
with open('FortInventory.txt', 'w') as out:
out.writelines(sorted(lines))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句