新手问题,我有以下代码,我需要将变量 gerrit 中的数据与列表 gerrit_refs 匹配并获取相应的匹配并保存在变量中,我该怎么做?
'''
gerrit_refs:
refs/changes/89/202089/4
refs/changes/39/205739/2
refs/changes/94/195594/6
refs/changes/90/202090/4
refs/changes/92/202092/4
'''
def main ():
gerrit=205739
with open('gerrit_refs.txt', 'r') as f:
# Here we make a list of refs based on the file
gerrit_refs = [line.strip() for line in f]
match = None
for ref in gerrit_refs:
if gerrit in ref:
match = ref
print match
break
if __name__ == '__main__':
main()
错误:-
TypeError: 'in' 需要字符串作为左操作数,而不是 in