0

我有一段代码遍历一个列表并搜索一个字符串,该列表是足球运动员的名字。它适用于几乎所有球员,但随机不会识别名为阿什利韦斯特伍德的球员。我检查了列表,他肯定在里面,一切都是小写的,脚本功能,因为它正在识别所有其他玩家(到目前为止)

基本上我在问使用'in'时会出现什么问题?我从中得到的数据库条目根本没有意义。

我已经包含了代码,虽然它有点脏而且不是很相关。

我也是一个相对的菜鸟。

代码

        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

这还没有认出这个名字,我不知道为什么?

任何人?

4

2 回答 2

0

if this_player in segment:

段的价值是什么?

于 2013-02-20T20:34:40.733 回答
0

段中的字符串“ashley westwood”可能有尾随空格。'阿什利韦斯特伍德'!='阿什利韦斯特伍德'

于 2013-02-20T20:45:12.860 回答