我有一个python程序,该程序从XML文件获取一个值并将其与给定的代码匹配,但是我不知道如何在某些条件下打印该值。
我的Python程序是:
class setMap(getXml):
def __init__(self, event_log_row):
self.event_log_row = event_log_row
def code(self):
for each in self.event_log_row:
self.get_map(each)
# if I use return here, it basically returns only one value, which is understandable.
def get_map(self, event_code):
dict_class = getXml() # Getting XML from another class
dictionary = dict_class.getdescription()
for keys, values in dictionary.items():
if keys == event_code:
return values
# I'm not allowed to use for loop or any conditions after this
code = ['1011', '1015', '1013']
obj = setMap(code)
print(obj.code())
能否实现我打算实现的目标,请问有人可以给我一些建议。
谢谢
您可以使用列表推导:
def code(self):
return [self.get_map(each) for each in self.event_log_row]
[print(x) for x in obj.code()]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句