我想檢查一個值是否在列表中的另一個之前。我問了一會兒這個問題:TypeError: 'GitHubIterator' object does not support indexing,它允許我訪問列表中的最後一條評論。我想展開此查看拉請求中的所有評論,看#hold-off
評論是否在#sign-off comment
之後。我可以使用print語句打印註釋,但是它錯誤地查看錯誤消息的值的順序:AttributeError: 'IssueComment' object has no attribute 'index'
。檢查一個值是否在列表中的另一個之前
我想我需要以某種方式獲得評論的主體列表,然後使用索引來確定順序,因爲迭代器不支持索引。但是我一直沒有成功實現這個目標。
hold_off_regex_search_string = re.compile(r"\B#hold-off\b", re.IGNORECASE)
sign_off_regex_search_string = re.compile(r"\B#sign-off\b", re.IGNORECASE)
for comments in list(GitAuth.repo.issue(prs.number).comments()):
print (comments.body)
if comments.index(hold_off_regex_search_string.search(comments.body)) > comments.index(sign_off_regex_search_string.search(comments.body)):
print('True')
你不能只是做一個're.search(R '#拖延[\ W \ S] +#簽收',comments.body)'這將返回匹配你的病情?我假設評論將以逗號分隔的單詞。 –