【发布时间】:2018-05-23 02:00:57
【问题描述】:
我有一个 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())
是否有可能实现我打算实现的目标,请有人给我一些建议。
谢谢
【问题讨论】:
-
python 2.x 还是 3.x ?还是您需要 100% 兼容的代码?
标签: python python-3.x python-2.7