LoginSignup
0
1

More than 1 year has passed since last update.

pythonでsqliteを利用しようとしたら、AttributeError: 'builtin_function_or_method' object has no attribute 'execute'とエラーが出た。

Posted at

エラー発生時の状況

sqliteを利用して、入力した文字を検索する辞書アプリを作成していたところ、下記のエラーが発生した。

エラー文

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Exception in Tkinter callback
Traceback (most recent call last):
  File "/Users/{user名}/.anyenv/envs/pyenv/versions/3.9.1/lib/python3.9/tkinter/__init__.py", line 1884, in __call__
    return self.func(*args)
  File "/Users/{user名}/Desktop/ejdict/jisyo.py", line 15, in search_dic
    rows = c.execute(sql, (word,))
AttributeError: 'builtin_function_or_method' object has no attribute 'execute'

解決方法

sqlite3に接続する際に、文法の誤りがあった。

    # データベースへ接続する
    conn = sqlite3.connect("ejdict.sqlite3")
    c = conn.cursor # cursorの後の「()」が抜けている。

正しくはこう

    # データベースへ接続する
    conn = sqlite3.connect("ejdict.sqlite3")
    c = conn.cursor()
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1