breaking a loop

wittempj@hotmail.com martin.witte at gmail.com
Thu Aug 11 16:22:31 EDT 2005


What you do is asking for a string, and then embed the result in '%'
characters, as this is what you do in the sql statement (btw: where is
the cursor defined?)

It is probably a better idea to construct the sql statement with the
direct result of raw_input, instead of format it straight away - see
below for the idea

martin at ubuntu:~ $ python
Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
py> s = raw_input('Prompt: ')
Prompt: exit
py> print s
exit
py> if s == 'exit':
...     print 'yes'
...
yes
py> t = '%%%s%%' %s
py> print t
%exit%
py> sql = "select * from TABLE where FIELD like %s", (s)
py> print sql
('select * from TABLE where FIELD like %s', 'exit')
py> sql = "select * from TABLE where FIELD like '%%%s%%" % s
py> print sql
select * from TABLE where FIELD like '%exit%
py>




More information about the Python-list mailing list