從解釋器我可以從MySQLdb發出>>>很好。所以,我假設模塊確實加載了。我的源如下所示:python2.6與MySQLdb,NameError'MySQLdb'未定義
from Tkinter import *
from MySQLdb import *
"""
Inventory control for Affordable TowingFunctions:
connection() - Controls database connection
delete() - Remove item from database
edit() - Edit item's attributes in database
lookup() - Lookup an item
new() - Add a new item to database
receive() - Increase quantity of item in database
remove() - Decrease quantity of item in database
report() - Display inventory activity
transfer() - Remove item from one location, receive item in another"""
def control():
....dbInfo = { 'username':'livetaor_atowtw', 'password':'spam', \
....'server':'eggs.com', 'base':'livetaor_towing', 'table':'inventory' }
....def testConnection():
........sql = MySQLdb.connect(user=dbInfo[username], passwd=dbInfo[password], \
........host=dbInfo[server], db=dbInfo[base])
........MySQLdb.mysql_info(sql)....testConnection()
control()
這給了我:
[email protected]:~/python/towing/inventory$ python inventory.py
Traceback (most recent call last):
..File "inventory.py", line 53, in
....control()
..File "inventory.py", line 26, in control
....testConnection()
..File "inventory.py", line 22, in testConnection
....sql = MySQLdb.connect(user=dbInfo[username], passwd=dbInfo[password], \
NameError: global name 'MySQLdb' is not defined
1)我要去哪裏錯了? 2)你們傢伙看到的其他遺漏嗎?
3)有關如何檢查到數據庫的有效連接(不只是服務器)的任何建議?
我一週,軟弱的靈魂忘了進口,它會影響名字空間的方式。謝謝你提醒我,我有多少白癡。你的解釋遠高於平均水平!我會*嘗試*不要再次忘記這節課。 – brad 2011-04-10 02:33:38