pythonspiit函数_Python:“str”对象不可调用

此代码适用于我正在处理的项目;我显然试图调用一个字符串。该程序旨在打印来自SQLite数据库的测验分数;方法1,这是我遇到的问题,应该给所有学生的正确课程和难度级别的最新记录。数据库看起来像这样;Python:“str”对象不可调用

CREATE TABLE Scores ( [Key] INTEGER, Score INTEGER NOT NULL, PupilName TEXT NOT NULL, Difficulty BOOLEAN NOT NULL, ClassNumber VARCHAR, DateTime DATETIME );

和代码(与调试的奇数位)这样的:

import sqlite3

#import collections

print ("Welcome to the Arithmetic Challenge high score table.")

def MainLoop():

DisplayType = input ("Please enter: 1 for highest scores by student in alphabetical order; 2 for highest scores, highest to lowest; 3 for average scores, highest to lowest. ")

Difficulty = input ("Enter difficulty level.")

ClassNumber = input ("Enter class number.") #Input of variables

conn = sqlite3.connect("QuizStorage")

c = conn.cursor()#Connects

c.execute("SELECT * FROM Scores")

PupilsEligible = c.fetchall()#Finds pupils

#count = collections.defaultdict(int) #?

#print (count)

print (PupilsEligible)

DifficultyInt = int(Difficulty)

if DisplayType == "1":

print (DifficultyInt)

c.execute("SELECT * FROM Scores WHERE Difficulty = (?) AND ClassNumber = (?) ORDER BY # DESC LIMIT 1 ORDER BY PupilName"(DifficultyInt, ClassNumber))

data = c.fetchall()

print (data)

elif DisplayType == "2":

c.execute("SELECT * , MAX(Score) FROM Scores WHERE Difficulty = (?) AND ClassNumber = (?) GROUP BY PupilName"(DifficultyInt, ClassNumber))

data = c.fetchall()

print (data)

elif DisplayType == "3":

c.execute("SELECT * , AVG(Score) FROM Scores WHERE Difficulty = (?) AND ClassNumber = (?) GROUP BY PupilName"(DifficultyInt, ClassNumber))

data = c.fetchall()

print (data)

else:

print ("That's not a valid answer.")

for row in c:

print (row)

conn.close()

MainLoop()

MainLoop()

请注意,该代码具有较早尝试是天堂”的各种遗物t还没有被剪掉。对不起,如果这使得它不清楚。 当我尝试运行它,我得到这个:

Welcome to the Arithmetic Challenge high score table.

Please enter: 1 for highest scores by student in alphabetical order; 2 for highest scores, highest to lowest; 3 for average scores, highest to lowest. 1

Enter difficulty level.2

Enter class number.3

[('Alice Mann',), ('Fred Pratt',), ('John Smith',), ('Karen James',)]

2

Traceback (most recent call last):

File "H:\My Documents\CA 2\ACHighScore 0.5.5.py", line 37, in

MainLoop()

File "H:\My Documents\CA 2\ACHighScore 0.5.5.py", line 19, in MainLoop

c.execute("SELECT * FROM Scores WHERE Difficulty = (?) AND ClassNumber = (?) ORDER BY # DESC LIMIT 1 ORDER BY PupilName"(DifficultyInt, ClassNumber))

TypeError: 'str' object is not callable

我已经看过了其他类似的错误,并已离开毫无收获。这个错误信息究竟意味着什么,以及如何避免?

2015-02-11

EctoPod

+3

您有'c.execute(“某个字符串”(数据))''。 Python认为你正试图调用一个字符串作为函数。 –

2015-02-11 09:59:45

+0

...在这里它应该是'c.execute(“一些字符串,其中blah =(?)和foo =(?)”,(x1,x2))'把这些值放在问号位置。你错过了一个逗号。 –

2015-02-11 10:03:41

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值