所以,我今天才开始使用 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/