hi everyone,
i have wrote the database code like this
try:
import MySQLdb
import _mysql_exceptions as DB_EXC

cxn = MySQLdb.connect(host='10.0.2.2')

if(cxn != 0):
tkMessageBox.showinfo("Text", "you can update ur local database to server")

else:
tkMessageBox.showinfo("Text", "there is no connection please try again")


cxn.close()

except ImportError , e:
return None

when there is connectivity then the control is going to the IF block. but when the connectivity loss the control is not going to the else block. is there any wrong in my syntax.
pls give a quick and valuable reply.

rajasekhar1242 try this.

import MySQLdb
import _mysql_exceptions as DB_EXC

try:
    cxn = MySQLdb.connect(host='10.0.2.2')

    if(cxn != 0):
        tkMessageBox.showinfo("Text", "you can update ur local database to server")

    else:
        tkMessageBox.showinfo("Text", "there is no connection please try again")

    cxn.close()

except ImportError , e:
    return None

What I found was imports after the try: and indents were wrong.
I used pyscripter | Syntax check too help find bugs. Also pylint helps also. pyscripter == mmm-experts.com

This article has been dead for over six months. Start a new discussion instead.