Fwd: cgi - cleaning tabs and returns out of textarea

Glenn Stauffer stauffer at swarthmore.edu
Mon Jan 28 12:16:19 EST 2002


Well, I think I found the answer.  I re-wrote my clean() function like this:

def clean(text):
	ws = re.compile('\s+')
	return ws.sub(' ', text)

I have to read up more on the re module since I'm not sure that I need to go 
through the compile step in this case.

By the way, I forgot to mention that I need to remove these whitespace 
characters form the form input data because I am storing it in a mysql 
database where form results accumulate and are later downloaded as 
tab-delimited text and loaded into excel.  Tabs and returns really mess 
things up when the data is extracted.

Thanks for the other suggestions.  I'll have to play around with it more and 
see what works best.

Glenn

-------------------------------------------------------------------------

Subject: cgi - cleaning tabs and returns out of textarea
Date: Mon, 28 Jan 2002 09:17:41 -0500
From: Glenn Stauffer <java at dejazzd.com>
To: python-list at cwi.nl

I have a cgi utility which I wrote to process form data and save key-value
pairs in a database.  Since it is a generic utility, I need to handle any
type of data and store it in a form that can be converted into a
tab-delimited download.

In many browsers, tabs and carriage returns can be embedded in a textarea
field and I need to strip them out of the input.




More information about the Python-list mailing list