【发布时间】:2018-07-16 05:41:08
【问题描述】:
我正在尝试如下更新 plist
匹配字符串字段“此提交中修复了哪些更改错误?”并更新<key>response</key>对应的字符串字段
现在的问题代码更新字符串字段What change bugs are fixed in this submission?,我如何更新相应的响应字符串字段?我也添加了预期的plist输出?有没有更简单的方法来做这个python?我哪里出错了?
代码:-
import re,os,fileinput
text1_to_search = re.compile(r'<string>What change bugs are fixed in this submission?.*</string>')
replacement1_text = """change://problem/219620> milestone: WCM-739#202 has failed to build in install: expected a type
change://problem/215275> Fix logic for PSK-->Open update
change://problem/1265279> Hotspot keeps changing from the device I selected
"""
for line in fileinput.input(filename, inplace=True, backup='.bak'):
print(text1_to_search.sub(replacement1_text, line)),
列表
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//company//DTD PLIST 1.0//EN" "http://www.company.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>28</key>
<dict>
<key>description</key>
<string>Which update of macOS, Xcode, and the SDKs was this submission built on with 'abc buildit'?</string>
<key>id</key>
<string>28</string>
<key>multiline</key>
<string>0</string>
<key>releases</key>
<array>
<string>milestone</string>
</array>
<key>response</key>
<string></string>
</dict>
<key>7</key>
<dict>
<key>description</key>
<string>What change bugs are fixed in this submission? (Please include the change number or URL followed by the title)</string>
<key>id</key>
<string>7</string>
<key>multiline</key>
<string>1</string>
<key>releases</key>
<array>
<string>milestone</string>
</array>
<key>response</key>
<string></string>
</dict>
</dict>
</plist>
更新后的预期输出
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//company//DTD PLIST 1.0//EN" "http://www.company.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>28</key>
<dict>
<key>description</key>
<string>Which update of macOS, Xcode, and the SDKs was this submission built on with 'abc buildit'?</string>
<key>id</key>
<string>28</string>
<key>multiline</key>
<string>0</string>
<key>releases</key>
<array>
<string>milestone</string>
</array>
<key>response</key>
<string></string>
</dict>
<key>7</key>
<dict>
<key>description</key>
<string>What change bugs are fixed in this submission? (Please include the change number or URL followed by the title)</string>
<key>id</key>
<string>7</string>
<key>multiline</key>
<string>1</string>
<key>releases</key>
<array>
<string>milestone</string>
</array>
<key>change://problem/219620> milestone: WCM-739#202 has failed to build in install: expected a type
change://problem/215275> Fix logic for PSK-->Open update
change://problem/1265279> Hotspot keeps changing from the device I selected</key>
<string></string>
</dict>
</dict>
</plist>
【问题讨论】: