On Dec 29, 6:05 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Sat, 29 Dec 2007 15:31:30 -0800 (PST), [EMAIL PROTECTED] declaimed
> the following in comp.lang.python:
>
>
>
> > I can't figure out why this doesn't work. Any ideas appreciated.
>
> > conn = MySQLdb.connect (db = "vocab")
>
>         This is a keyword parameter association, the parameter named "db" is
> given the string value "vocab".
>
> > import defs
> > conn = MySQLdb.connect (defs.connect)
> > where defs.py is
>
> > connect = 'db = "vocab"'
>
>         This is a string.  You'd get the same error using:
>
> conn = MySQLdb.connect('db="vocab"')
>
> as you are giving the entire string to whatever the first defined
> parameter in .connect() is...
>
> Change defs.py to:
>
> -=-=-=-=-
> connect = { "db" : "vocab" }
>
> and change the connection to read:
>
> -=-=-=-=-
> conn = MySQLdb.connect(**defs.connect)
>
> to force keyword unpacking of the dictionary
>
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         [EMAIL PROTECTED]              [EMAIL PROTECTED]
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               [EMAIL PROTECTED])
>                 HTTP://www.bestiaria.com/


Thanks. This works great. As a side note, it can also be extended so
that if defs.py is

connect = { "host" : "localhost", "user" : "joey", "db" : "vocab" }

the MySQLdb.connect(**defs.connect) still works.





-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to