Another MySQL Problem
Stephen Hansen
me+list/python at ixokai.io
Wed Jun 23 10:55:52 EDT 2010
On 6/23/10 6:45 AM, Victor Subervi wrote:
> Hi;
> I have this line:
>
> cursor.execute('select clientEmail from clients where client=%s',
> (string.replace(client, '_', ' ')))
> clientEmail = cursor.fetchone()[0]
> cursor.execute('select * from %s' % (client))
>
> client = "Lincoln_Properties"
> With the replacement, the interpreter complains that mydatabase.Lincoln
> doesn't exist. Therefore, the first line of code isn't putting the %s
> replacement in quotes, as I was told by you all it would. So I add
> quotes to it and the interpreter complains on the second line of code
> that it's unsubscriptable (because it's None). What gives?
Its very early, so excuse me if I fall asleep in the middle of the response.
First: Don't do 'string.replace(your_string, x, y)' -- that's back in
the very, very old days before strings themselves had all the nice methods.
Do, 'client.replace("_", " ")' instead.
Second, you're forgetting a cardinal rule. Always, always, always,
include the actual tracebacks when reporting errors. Don't summarize them.
Third, I *think* the problem is-- though I may be wrong here, because
again, just woke up-- that you're not passing the options as a tuple.
Consider: ("hello") is not a tuple with one item. This is a slight
'wart' with Python syntax. Parens do not make tuples: *commas* do.
Therefore, every tuple *must* have a comma. To make a one-item tuple,
you must do ("hello", )
--
Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100623/a3fe3fe6/attachment-0001.sig>
More information about the Python-list
mailing list