인터프리터에서 >>>를 MySQLdb에서 정상적으로 실행할 수 있습니다. 그래서 모듈이 실제로로드되었다고 가정합니다.Python2.6 with 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
한 다음 내 소스 보인다?
2) 다른 사람이 본 사람이 있습니까?
3) 서버뿐만 아니라 데이터베이스에 대한 유효한 연결을 확인하는 방법에 대한 조언이 있습니까?
내 주, 미약 한 마음이 가져 오기를 잊어 버렸고 네임 스페이스에 영향을주는 방식을 잊어 버렸습니다. 내가 얼마나 바보인지 나에게 상기시켜 줘서 고마워. 당신의 설명은 평균 이상이었습니다! 나는이 교훈을 다시 잊지 않을 것입니다. – brad