【发布时间】:2019-12-05 11:08:26
【问题描述】:
def abc(filename):
infile = open(filename, 'r+')
read = infile.read()
lst = read.split()
for i in lst:
if len(i) == 4:
i.replace(i, 'abcd')
print(i)
abc('question 4.txt')
我想替换我的文本文件中的 4 个字符串,但显然这没有发生。一切似乎都运行良好,但替换功能没有响应。
【问题讨论】:
-
@cocool97 - 刚刚意识到
标签: python python-3.x for-loop replace user-defined-functions