【发布时间】:2016-01-13 04:36:18
【问题描述】:
这是我创建瑞士配对系统的代码,该系统会为比赛生成配对球员:
def swissPairings():
db = psycopg2.connect("dbname=tournament")
c = db.cursor()
c.execute("select PlayerID from Scores order by Wins;")
ids = c.fetchall()
c.execute("select Players.Name from Players join Scores\
on Players.PlayerID = Scores.PlayerID\
order by Wins;")
names = c.fetchall()
standings = playerStandings()
pairs = zip(ids,names)
print pairs
db.close()
当我为实际配对运行测试时,我确实得到了一个如下列表(但它看起来有点有趣,它应该生成两对,因为有四个玩家,但它却生成了一个长列表):
[((291,), ('Fluttershy',)), ((293,), ('Pinkie Pie',)), ((290,),
('Twilight Sparkle',)), ((292,), ('Applejack',))]
但是后面跟着错误信息:
Traceback (most recent call last):
File "/Users/Rebecca/fullstack/vagrant/tournament/tournament_test.py", line 136, in <module>
testPairings()
File "/Users/Rebecca/fullstack/vagrant/tournament/tournament_test.py", line 116, in testPairings
if len(pairings) != 2:
TypeError: object of type 'NoneType' has no len()
如何解决此错误?似乎我必须附加一些东西,但我不知道是什么...我需要使 len(pairings) == 2,现在它似乎是 1。
【问题讨论】:
标签: python database list postgresql typeerror