我的问题是在注释列中,我想将上面显示的列表样式更改为类似以下内容:
我的意思是注释列值具有多种样式,我只想将该样式更改为我的样式即可:)
示例:
['flight_search.price_range'] ==> ['flight-search price range']
['flight_search.stops'] ==> ['flight-search stop']
['flight_search.date.depart_origin'] ==> ['flight-search date depart origin']
并完成此转换后,将其完全替换为旧的注释列:)
注释样本:
anotation
['flight_search.destination1']
['flight_search.origin']
['flight_search.destination1']
['flight_search.type']
['flight_search.type']
['flight_search.airline']
['flight_search.stops']
['flight_search.stops']
['flight_search.price_range']
['flight_search.price_range']
['flight1_detail.from.time']
['flight_search.date.depart_origin']
Python字符串replace()方法可以是一个选项。但是我看到您希望第一个下划线是-,第二个下划线是空格。我认为,如果您深入研究python中的正则表达式,则可以解决该问题。为简单起见,到目前为止,我已经做到了:
mystring = 'flight_search.price_range'
mystring = mystring.replace("_", "-")
mystring = mystring.replace(".", " ")
参见https://www.w3schools.com/python/ref_string_replace.asp
编辑的代码:
mystring = 'flight_search.price_range'
mystring = mystring.replace("_", "-",1)
mystring = mystring.replace(".", " ")
mystring = mystring.replace("_", " ")
print(mystring)
编辑代码的结果:航班搜索价格范围
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句