代码是:
with sqlite3.connect('example.db', detect_types=sqlite3.PARSE_DECLTYPES) as conn:
curr = conn.cursor()
vals = ( surveyname , surveydesc , dictObj ,)
curr.execute("INSERT INTO Surveys(Name, Desc, DictObject) VALUES (?, ?, ?)", vals)
我得到的错误是:
C:\Python26\html\xlsxhelper.py in register_survey(surveydict={u'q1': {'n': 3, 'nselect': 1, 'qn': 1, 're': {u'a': {'n': 3, 'text': u'\ud30c\ub791'}}, 'text': u'\uc88b\uc544\ud558\ub294 \uc0c9\uae54\uc740?', 'type': 0}, u'q2': {'n': 3, 'nselect': 2, 'qn': 2, 're': {u'a': {'n': 3, 'text': u'\ub625'}}, 'text': u'\uc88b\uc544\ud558\ub294 \uacfc\uc790\ub294? (2\uac1c\uc120\ud0dd)', 'type': 0}, u'q3': {'n': 1, 'nselect': 1, 'qn': 3, 're': {u'a': {'n': 1, 'type': 0}}, 'text': u'\ubd84\ub958', 'type': 1}, u'q4': {'n': 1, 'nselect': 1, 'qn': 4, 're': {u'a': {'n': 1, 'type': 1}}, 'text': u'\uccb4\ud06c', 'type': 1}, 'qn': 4}, surveyname='qwe', surveyinfo='Survey Description\r\nqwe')
101 with sqlite3.connect('example.db', detect_types=sqlite3.PARSE_DECLTYPES) as conn:
102 curr = conn.cursor()
103 vals = (surveyname , surveydesc , dictObj) <= somehow this line is highlighted
104 curr.execute("INSERT INTO Surveys(Name, Desc, DictObject) VALUES (?, ?, ?)", vals)
105 conn.commit()
vals undefined, surveyname = 'qwe', surveydesc undefined, dictObj = 'eJwLVg8uLSpLrVRwSS1OLsosKMnMz4spiskrLE9V5yow5NIDANCTC5w=\n'
<type 'exceptions.TypeError'>: function takes at most 2 arguments (4 given)
args = ('function takes at most 2 arguments (4 given)',)
message = 'function takes at most 2 arguments (4 given)'
函数最多接受 2 个参数是什么意思?我在这里调用什么函数?curr.execute
接受 2 个参数:实际查询和参数。为什么第 103 行突出显示?这是一个简单的元组赋值。
调查名称和调查名称是简单的字符串。dictObj 是一个经过腌制并压缩成字符串的字典。因此,将三个字符串插入到具有 text/text/blob 列的行中。我找不到这里有什么问题..