python - 在哪里定义Python类,mysql连接?

标签 python mysql debugging attributeerror

所以,我今天才开始使用 python。我安装了 python-mysql.connector 这样我就可以开始编写一些查询并在 python 中处理结果,然后将一些数据输出到 lcd 屏幕。

就知道这就是我所拥有的......

#!/usr/bin/python

import Adafruit_CharLCD
import mysql.connector

class LCDTests:

    def __init__(self):

        self.lcd = Adafruit_CharLCD;
        #self.lcd.begin(16,1);

        try:
            cnx = mysql.connector(user = '', password='' database='', host='')
        except mysql.connector.Error, e:
            try:
                print "MySQL Error [%d]: %s" % (e.args[0], e.args[1])
            except IndexError:
                print "MySQL Error: %s" % str(e)            
        else:
                cnx.close()

    def run(self):
            print('alex')
            #lcd.message('loading...');

test = LCDTests()
test.run()

但是每当我运行 ./test.py 时,我都会得到以下输出:

Traceback (most recent call last):
  File "./test.py", line 31, in <module>
    test = LCDTests()
  File "./test.py", line 16, in __init__
    cnx = mysql.connector(user = '...', password='...', database='...', host='...')
TypeError: 'module' object is not callable

在搜索问题时,我发现的任何东西都没有真正帮助我解决问题...有什么想法可能是问题所在吗?

最佳答案

mysql.connector.connect(...) 不是 mysql.connector(...)

module docs对您来说可能是一个很好的资源。

关于python - 在哪里定义Python类,mysql连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14364894/

相关文章:

Python SocketServer死锁问题

mysql - 在 MySQL InnoDB 中存储大于 max_allowed_pa​​cket 的 BLOB 的最佳方法

android - 在设备上运行 Android systrace

linux - 内核 - 从 Linux 系统调试 Windows 客户机系统 - 安装程序不工作

python - Django - 使用 REMOTE_USER 进行身份验证 - 如何在开发服务器中进行测试?

python - 如何在 Maya 上检索 cmds.polyExtrude 创建的顶点

python - 使用 Django 在 JSONField 上进行选择

python - scikit 混淆矩阵中标量变量的索引无效

php - 如何防止 php 在注销后返回页面?

mysql - 是否可以通过主键的一部分对 DQL 查询进行分组并返回具有 max() 日期时间记录(早于引用日期)的记录?