【问题标题】:How do I solve a TypeError module [duplicate]如何解决 TypeError 模块 [重复]
【发布时间】:2014-09-05 16:04:29
【问题描述】:

我使用 sqlite3 作为数据库。

我正在尝试执行我的 SQL 查询:

sql = "INSERT INTO info_calc (application, version, path, os, user, ip) VALUES (?, ?, ?, ?, ?, ?)"
args = my_argv[2], my_argv[3], my_argv[4], sys.platform, getpass().getuser(), machine

c.execute(sql, args)

但我有这个错误:

args = my_argv[2], my_argv[3], my_argv[4], sys.platform, getpass().getuser(), machine
TypeError: 'module' object is not callable

我已经看过这个帖子:TypeError: 'module' object is not callable,但他们谈到了套接字。

【问题讨论】:

  • 这个错误和你看到的帖子一样,只是模块不同。

标签: python sql database sqlite arguments


【解决方案1】:

getpass 是一个模块,你正在调用它:

getpass().getuser()

删除第一个()

>>> import getpass
>>> getpass()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> getpass.getuser()
'mj'

【讨论】:

  • 老实说,你让我吃惊……我几个小时前又发了一个问题,没有人给我正确的答案(我知道这不是 SQL 语法的问题)。
  • @Glacius:我能看到的上一个问题是 Python 字符串语法错误。我注意到那里的答案正确地使用了getpass,顺便说一句。
猜你喜欢
  • 2012-05-26
  • 1970-01-01
  • 2014-02-20
  • 2011-09-10
  • 2023-02-25
  • 1970-01-01
  • 2021-12-25
  • 1970-01-01
  • 2014-09-01
相关资源
最近更新 更多