SQLite3; weird error
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Mon Oct 29 16:12:02 EDT 2007
TYR a écrit :
> Has anyone else experienced a weird SQLite3 problem?
>
> Going by the documentation at docs.python.org, the syntax is as
> follows:
> foo = sqlite3.connect(dbname) creates a connection object representing
> the state of dbname and assigns it to variable foo. If dbname doesn't
> exist, a file of that name is created.
>
> To do anything with it, you then need to create a cursor object by
> calling foo's method cursor (bar = foo.cursor).
You actually want :
bar = foo.cursor()
In Python, the parens are not optional when it comes to calling
functions - in fact, parens *are* the call operator. Without them, you
don't call the function (or method), but retrieve a reference to it.
>
> You can now pass an SQL query or command to the DB by calling the
> cursor object's method execute() with the SQL query as a quoted
> statement.
>
> (bar.execute("SELECT FROM squid WHERE squamous=True")
>
> And then do other stuff.
>
> Fine. When I call the cursor object, though, I get an AttributeError;
> ('builtinfunction_or_method object has no attribute 'execute')
Indeed. cf above.
More information about the Python-list
mailing list