我有一个连接数据库的功能。此代码有效:
def connect():
return MySQLdb.connect("example.com", "username", "password", "database")
但这不是:
def connect():
host = "example.com"
user = "username"
pass = "password"
base = "database"
return MySQLdb.connect(host, user, pass, base)
为什么会这样?
答案 0 :(得分:8)
pass
是保留关键字。
选择不同的变量名称,您的代码应该可以正常工作 也许是这样的:
def connect():
_host = "example.com"
_user = "username"
_pass = "password"
_base = "database"
return MySQLdb.connect(_host, _user, _pass, _base)