MySQLdb and regular expression in python -
import mysqldb x=raw_input('user> ') y=raw_input('passwd> ') db=mysqldb.connect(host="localhost", user="%s", passwd="%s" % x,y) cursor=db.cursor() cursor.execute('grant on squidctrl.* sams@localhost identified "connect";') cursor.execute('grant on squidlog.* sams@localhost identified "connect";') cursor.close()
question how can use right, don't want enter username , password in script in beginning, want myself wish. when try run put username , pass, after mistake
traceback (most recent call last): file "test.py", line 8, in <module> db=mysqldb.connect('host="localhost", user="%s", passwd="%s"' % x,y) typeerror: not enough arguments format string
you don't need use string interpolation ("%s" % ...
) here.
import mysqldb user = raw_input('user> ') password = raw_input('passwd> ') db=mysqldb.connect(host="localhost", user=user, passwd=password) cursor=db.cursor() cursor.execute('grant on squidctrl.* sams@localhost identified "connect";') cursor.execute('grant on squidlog.* sams@localhost identified "connect";') cursor.close()
Comments
Post a Comment