2009-04-16 21 views
1

我有一點Python連接到一個數據庫與切換投入本地與現場。這是如何「轉讓之前引用」?

LOCAL_CONNECTION = {"server": "127.0.0.1", "user": "root", "password": "", "database": "testing"} 
    LIVE_CONNECTION = {"server": "10.1.1.1", "user": "x", "password": "y", "database": "nottesting"} 

    if debug_mode: 
     connection_info = LOCAL_CONNECTION 
    else: 
     connnection_info = LIVE_CONNECTION 
    self.connection = MySQLdb.connect(host = connection_info["server"], user = connection_info["user"], passwd = connection_info["password"], db = connection_info["database"]) 

做工精細本地(Windows中,Python的2.5),但生活(Linux的,Python 2.4中)我得到:

UnboundLocalError: local variable 'connection_info' referenced before assignment 

我看到了同樣的錯誤,即使我刪除if/else和只需將連接信息直接分配給LIVE_CONNECTION值即可。如果我將實時連接值硬編碼到最後一行,則全部工作。顯然我很困。我沒有看到什麼?

回答

16

第二個分配拼寫錯誤。

你用3個n寫了connnection_info = LIVE_CONNECTION

+0

3個n's很難看! – 2009-04-16 01:32:57

相關問題