文档的特定位置替换字串

def fun_getBinCountToProject():
with open("../aps/application/radisson/formal/sys_common_guiobj/app_guiobj_setup.c", "r") as project_op:
temStr = '#define CONFIG_FLASH_BIN_COUNT ' + str(len(g_listBin));
content = project_op.read();

pos = content.find('#define CONFIG_FLASH_BIN_COUNT');
if pos != -1:
pos_end = content[pos:].find(' ');
content = content[:pos] + temStr + content[pos + pos_end:];
with open("../aps/application/radisson/formal/sys_common_guiobj/app_guiobj_setup.c","w") as project_op:
project_op.write(content);
原文地址:https://www.cnblogs.com/jiangzhaowei/p/6626637.html