[mod_python] Problem with html quoted/unquoted

Jim Gallacher jpg at jgassociates.ca
Tue May 23 07:50:18 EDT 2006


Trevor Hennion wrote:
> Wouter van Marle wrote:
>> On Tue, 2006-05-23 at 01:49 -0400, Joshua Ginsberg wrote:
>>> Wouter --
>>>
>>> You used % to do string substitution on the first argument to 
>>> execute() as opposed to passing a tuple as a second argument to 
>>> execute().
>>
>> I don't get your meaning.
>> Can you please give me the lines of code as example? Thanks!
>>
>> Wouter.
>>
> 
> Wouter,
> 
> I have been stuggling to understand this as well
> 
> I believe that it should look like this:
> 
> s = """This is 'some' stuff with "quotes" and stuff"""
> cursor.execute('INSERT INTO testtable (field1) VALUES (%s)', (s,))
> 
> If this is incorrect please somebody put me right!

Your code snippet is correct. If you only have one parameter you don't 
need to wrap it in a tuple although that may be dependent on the DBI 
implementation. I usually wrap it anyway as you have done just to keep 
my code consistent.

Jim


More information about the Mod_python mailing list