【发布时间】:2020-09-17 23:21:33
【问题描述】:
如何解决这个错误?! 代码是
from datetime import datetime
with open("1.txt") as f:
lines = f.readlines()
lines[1] = datetime.today().strftime('%A %d %B %Y at %I:%M %p')
with open("1.txt", "w") as f:
f.writelines(lines)
错误
File "test.py", in <module>
lines[1] = datetime.today().strftime('%A %d %B %Y')
IndexError: list assignment index out of range```
【问题讨论】:
标签: python list indexing variable-assignment