【发布时间】:2020-09-07 10:32:15
【问题描述】:
【问题讨论】:
标签: python text file-handling
【问题讨论】:
标签: python text file-handling
你可以试试这个:
import re
regex = r"(?<=CRC_END\n)(.*)(;)"
subst = "newvalue "
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, YOUR_STRING, 0, re.MULTILINE)
if result:
print (result)
【讨论】:
对于行中的行: 计数=计数+1 如果“CRC16”在行: crcLineNumber = 计数
Lines[crcLineNumber-1] = inputCrc[:-1].upper()+"h ; CRC16 - checksum, MSB - LSB\n"
file1.close()
【讨论】: