我有一段迭代遍歷列表並搜索字符串的代碼,該列表是足球運動員的名字。它適用於幾乎每個球員,但隨機不會識別一個名爲阿什利韋斯特伍德的球員。我已經檢查了清單,他肯定在那裏,一切都是小寫,腳本的功能,因爲它是承認每一個其他球員(到目前爲止)在python中搜索一個字符串時出現Unfathomable(對我而言)問題
基本上我問在使用'in'時會發生什麼問題?我從這裏得到的數據庫條目根本沒有意義。
我已經包含代碼,雖然它有點髒,並沒有真正相關。
我也是親戚。
CODE
if 'corner' in text3[:50] or ('inswinging corner' in text3) or ('outswinging corner' in text3) :
print text3
print time
for player in away_players_names:
this_player = player[0].lower()
upper = player[0]
if this_player in segment:
player_id = away_team_dict[upper]
player_id = int(player_id[0])
etype = 10
team = 2
cur.execute("""INSERT INTO football.match_events(type, player, time, game_id, team) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE game_id = game_id""", (etype, player_id, time, game_id, team))
db.commit()
for player in home_players_names:
this_player = player[0].lower()
print this_player
upper = player[0]
if this_player in segment:
player_id = home_team_dict[upper]
player_id = int(player_id[0])
etype = 10
print player_id
team = 1
cur.execute("""INSERT INTO football.match_events(type, player, time, game_id, team) VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE game_id = game_id""", (etype, player_id, time, game_id, team))
db.commit()
這裏是印刷聲明和故障的一個例子。
corner taken right-footed by ashley westwood to the near post
38.22
bradley guzan
ron vlaar
ciaran clark
nathan baker
matthew lowton
charles n'zogbia
ashley westwood
fabian delph
christian benteke
jordan bowery
andreas weimann
shay given
joe bennett
yacouba sylla
simon dawkins
barry bannan
darren bent
brett holman
這沒有認出名字,我不知道爲什麼?
有人嗎?
段是什麼? – Hoopdady 2013-02-20 20:40:37