473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Python and MySQL server

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,insertEntryCateg ory))

Thanks, Any help is appreciate it.

Mr. Frodo

Jul 21 '05 #1
1 1197
Unknown a écrit :
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 : ') <q_and_d>
searchWhat = "%%%s%%" % raw_input ('Search for : ')

You have to double the % symbol to escape it.
</q_and_d>

You'd better be *very* careful with user input, specially when you use
it like this: cursor.execute('select * from tableName where contentField like
%s',(searchWhat))
Please consider checking and cleaning user inputs before using'em in a
query.

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?


Launch a text-mode editor with a temp file name and read back that file
if it exists once the editor is closed. Pseudo code:

fname = create_a_name_that_dont_exists_yet()
openEditor() # block until the editor is closed
if os.path.file_exists(fname):
text_to_insert = open(fname).read()
# ...
My 2 cents...


Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Zunbeltz Izaola | last post by:
Hi! I am planning a program and I need some advice about what tool to use. Basically my program will deal with a object A. A is a list like object with same attributtes and a list of objects...
5
by: sandy | last post by:
Hi All, I am a newbie to MySQL and Python. At the first place, I would like to know what are the general performance issues (if any) of using MySQL with Python. By performance, I wanted to...
8
by: Alec Wysoker | last post by:
I need to be able to access mySQL 4.0 and 4.1 databases from python. I was hoping to find mysql-python 1.2.0 already built for Sparc, but no such luck. I've been struggling trying to get it...
2
by: Daniel Frickemeier | last post by:
Hi, I have a strange problem. I´m developing a small python-program wiht the mysql-python-module. The program should run on a server without any mysql-installation. Is there any posibility to...
2
by: francescomoi | last post by:
Hi. I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2: ---------------------------------- # export PATH=$PATH:/usr/local/mysql/bin/ # export mysqlclient=mysqlclient_r # python setup.py...
10
by: callmebill | last post by:
I'm getting my feet wet with making Python talk to MySQL via ODBC. I started on Windows, and it went smoothly enough due to the ODBC stuff that apparently is native to Python at least on windows...
2
by: Richard Brosnahan | last post by:
I hate asking questions that have probably been answered before, but I have not found a way to conveniently search the archives of this mailing list. So... Can someone tell me how to...
15
by: John Nagle | last post by:
I've been installing Python and its supporting packages on a dedicated server with Fedora Core 6 for about a day now. This is a standard dedicated rackmount server in a colocation facility,...
1
by: Steve Ametjan | last post by:
I've been trying to get MySQL-python to install on Leopard for the past couple of days, and I keep running into relatively the same error. I'm hoping that someone on this list will be able to...
8
by: Roy Smith | last post by:
Does there exist a pure Python version of a MySQL module? I've got a data logging application that needs to run on a whole bunch of OSs, ranging from Windows to a dozen different unix flavors on...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.