Python and MySQL server

Unknown frodo at fortress.site
Thu Jul 14 15:59:54 EDT 2005


Python 2.4
Linux kernel 2.6.12

Hi,

1. How do I make the following statement to search for all Strings I
input from console?

for example, with the code below I need to enter %hello world% (yeah,
including the % symbols) to find all entries for hello world on the
tableName. But I want to set the % symbols on the code itself so I don't
have to input manually the % at the prompt.

searchWhat = raw_input ('Search for : ')
cursor.execute('select * from tableName where contentField like
%s',(searchWhat))

2. I'm entering data by copying and pasting. Much of the text is in
multiple lines and some formated sections such as paragraphs,
indentations, double lines and what not.

How do I enter keep the formated text intact if entering from console? Now
it loses all formatting and I have to copy and paste text line by line
because it won't take the multiple lines.

insertEntryId = raw_input('New Entry ID: ')
insertEntryContent = raw_input('New Entry Content: ')
insertEntryCategory = raw_input('New Category: ')

cursor.execute('insert into tableName values (%s,%s,%s)',
(insertEntryId,insertEntryContent,insertEntryCategory))

Thanks, Any help is appreciate it.

Mr. Frodo




More information about the Python-list mailing list