Re: ValueError: too many values to unpack
Jim Vickroy <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Rich Shepard wrote:
> My application has a table named 'model' with this schema:
>
>CREATE TABLE model (model_name TEXT NOT NULL PRIMARY KEY,
>model_desc TEXT, model_type TEXT, keName TEXT, agent INTEGER);
>
>and it holds one record.
>
> During testing I created a new database and inserted values in each of
>these fields. But, when I open the existing database to read each column and
>insert the values in the appropriate GUI widgets, I get the error message on
>the subject line:
>
> File "/data1/eikos/modelPage.py", line 198, in OnOpenMod
> for (model_desc, model_type, keName, agent) in self.appData.cur:
>ValueError: too many values to unpack
>
> What I'm trying to do in this method (starting at line 197) is,
>
> self.appData.cur.execute("select * from model")
> for (model_desc, model_type, keName, agent) in self.appData.cur:
> modDesc = model_desc
> mType = model_type
> knowlEng = keName
> method = agent
> self.tcDesc.SetValue(modDesc)
> self.modType.SetString(self.modType.SetSelection(mType))
> self.keName.SetValue(knowlEng)
> self.agent.SetSelection(method)
>
> My newness to pysqlite is undoubtably the reason why I have the syntax
>incorrect, and I did read the appropriate section in the on-line doc on how
>to extract each table record into a local variable. I thought the 'for ...'
>loop syntax was appropriate when there's a single record, and I did not need
>to use fetchone(). What is the appropriate syntax?
>
>Rich
>
>
>
Hello Rich,
Your table has 5 columns, but, in the for-loop statement, you are trying
to unpack a fetched row into only 4 columns.
Either modify the select statement to retrieve only 4 columns or modify
the for-loop statement to accept 5 columns.
-- jv