def replace_first_line(file, replacement):
# suppress a type error which was confusing
if type(file) is not InMemoryUploadedFile:
with open(file, 'r', encoding='iso-8859-1') as f:
data = f.readlines()
if "!DOCTYPE" not in data[0]:
data[0] = replacement
with open(file, 'w') as f:
f.writelines(data)
评论列表
文章目录