user114060
user114060

Reputation:

Help with basic Python function

I have a function to connect to a database. This code works:

def connect():
    return MySQLdb.connect("example.com", "username", "password", "database")

But this doesn't:

def connect():
    host = "example.com"
    user = "username"
    pass = "password"
    base = "database"
    return MySQLdb.connect(host, user, pass, base)

Why so?

Upvotes: 4

Views: 180

Answers (1)

Jon W
Jon W

Reputation: 15826

pass is a reserved keyword.

Pick different variable names and your code should work fine.
Maybe something like:

def connect():
   _host = "example.com"
   _user = "username"
   _pass = "password"
   _base = "database"
   return MySQLdb.connect(_host, _user, _pass, _base)

Upvotes: 8

Related Questions