我有一些代码可以使用以下代码解析从 url 获得的 xml 文件:
pattern4 = re.compile('title=\'Naps posted: (.*) Winners:')
pattern5 = re.compile('Winners: (.*)\'><img src=')
for row in xmlload1['rows']:
cell = row["cell"]
##### defining the Keys (key is the area from which data is pulled in the XML) for use in the pattern finding/regex
user_delimiter = cell['username']
##### the use of the float here is to make sure the result of the strike rate calculations returns as a decimal, otherwise python 2 rounds to the nearest integer!
user_numberofselections = float(re.findall(pattern4, user_delimiter)[0])
user_numberofwinners = float(re.findall(pattern5, user_delimiter)[0])
strikeratecalc1 = user_numberofwinners/user_numberofselections
strikeratecalc2 = strikeratecalc1*100
##### Printing the results of the code at hand
print "number of selections = ",user_numberofselections
print "number of winners = ",user_numberofwinners
print "Strike rate = ",strikeratecalc2,"%"
print ""
getData()
我不知道是否可以过滤数据并打印不同的打印列表。我想我必须描述一个我想要实现的例子:
如果strikeratecalc2 => 20% 但也<30% 打印"X Strike rate = ",strikeratecalc2,"%"
如果strikeratecalc2 => 30% 但也<40% 打印"Y Strike rate = ",strikeratecalc2,"%"
如果strikeratecalc2 => 40% 但也<50% AND user_numberofselections >100 打印“Z Strike rate = ",strikeratecalc2,"%"
如果strikeratecalc2 => 50% AND user_numberofselections >100 打印“ZA Strike rate = ",strikeratecalc2,"%"
如果有人能够为我认为可能是一项简单的任务提供一些解决方案,我将能够根据我的需要对答案进行逆向工程。如果需要更多信息,请告诉我。亲切的问候