ここで学ぶ機会。ファイル内の特定のプロパティを更新している状況があります。ファイルを更新する関数があります:
def update_tiapp(property, value):
print 'update_tiapp: updating "%s" to "%s"' % (property, value)
for line in fileinput.input(os.path.join(app_dir, 'tiapp.xml')): # , inplace=True
if property is 'version':
line = re.sub(r'(<version>).*?(</version>)', '\g<1>%s\g<2>' % value, line.strip(), flags=re.IGNORECASE)
elif property is 'brand':
line = re.sub(r'(<property name="brand" type="string">).*?(</property>)', '\g<1>%s\g<2>' % value, line.strip(), flags=re.IGNORECASE)'\g<1>%s\g<2>' % value, line.strip(), flags=re.IGNORECASE)
elif property is 'banner-bmp':
line = re.sub(r'(<banner-bmp>).*?(</banner-bmp>)', '\g<1>%s\g<2>' % value, line.strip(), flags=re.IGNORECASE)
elif property is 'dialog-bmp':
line = re.sub(r'(<dialog-bmp>).*?(</dialog-bmp>)', '\g<1>%s\g<2>' % value, line.strip(), flags=re.IGNORECASE)
elif property is 'url':
line = re.sub(r'(<url>).*?(</url>)', '\g<1>%s\g<2>' % value, line.strip(), flags=re.IGNORECASE)
dialog-bmp
&以外の条件はすべて問題ありませんbanner-bmp
。理解できない、または見つけられない何らかの理由で、条件が一致しません。プロパティと条件を に変更するとdialog
、python は喜んで一致し、変更を加えてくれます。
なに?!
これは簡単な変更であり、作成してもかまいませんが、理解したいと思います。
すべてを吹き飛ばすハイフンについてはどうですか? ここでは文字列の一致だけではありませんか、それとも内部で予期していなかった何かが起こっているのでしょうか?