我已经在文本文件mobileBuildSettings中搜索了由用户输入确定的特定字符串,并且已经复制了这些字符串。我测试过,这段代码工作得很好。
我的问题如下:然后我尝试在名为abproject的构建文件中搜索@ AppIdentifier @,并将其替换为在mobileBuildSettings中找到的字符串。我的代码没有给出任何错误,但是它什么也没做。
下一个代码块在mobileBuildSettings文件中搜索用户输入的CUID的appID,displayName,bundleVersion和andoidVersionCode。该代码可以正常工作
projectFile = open("C:/settings/mobileBuildSettings.txt" , "r")
for line in projectFile:
CUID = str(CUID)
if CUID + " - " in line:
appIdentifier = next(projectFile).split("=")[1]
displayName = next(projectFile).split("=")[1]
bundleVersion = next(projectFile).split("=")[1]
next(projectFile)
androidVersionCode = next(projectFile).split("=")[1]
print (appIdentifier, displayName, bundleVersion, androidVersionCode)
break
以下代码没有任何错误,但据我所知它没有任何作用。该代码应在abproject文件中找到appID,并将其替换为mobileBuildSettings文件中的appID。
abproject = open("C:/abproject.build", "r")
#appIdentifier = str(appIdentifier)
apid = ("@AppIdentifier@")
for line in abproject:
if ("@AppIdentifier@") in abproject:
#line=line.replace(("@AppIdentifier@"),appIdentifier)
这是我尝试过的代码,但也不起作用。
print(line.replace(apid, appIdentifier))
break
abproject.close()
我几天前不得不做同样的事情,这是我的解决方案:
这是一些代码:
with open("originalFile.txt", "r+") as script, open("tempfile.txt", "w+") as newscript :
#Go through the file line by line
for line in script.readlines():
#print(line)
#Search for a specific pattern in the line (line object is a string)
if line[4:12] == "MyPattern" :
#Replace this line by an other
newscript.write("myText")
else :
#Else, add the standard line to the temp file
newscript.write(line)
#Close both files
script.close()
newscript.close()
#Delete the old file, and rename the file with replaced text
os.remove("originalFile.txt")
os.rename("tempfile.txt", "originalFile.txt")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句