MySQLdb, lots of columns and newb-ness

Ant antroy at gmail.com
Wed Dec 20 10:00:38 EST 2006



On Dec 20, 5:20 am, Andrew Sackville-West <and... at farwestbilliards.com>
wrote:
> > >>> values = ", ".join([escapeAndQuote(f[:-2]) for f in fields])

Obviously this is the appropriate choice since this is a database app.
In general the strip() group of string methods do what you want in a
safe way - assuming you don't care about whitespace:

>>> s = "   test   \r\n"
>>> s.strip()
'test'
>>> s.rstrip()
'   test'
>>> s.lstrip()
'test   \r\n'

If you are concerned about whitespace:
>>> s.strip("\n\r")
'   test   '

strips any \n's or \r's from the ends of the line.

This way it doesn't matter what your line endings are -  you won't be
surprised by missing characters if the data dump changes for any
reason.




More information about the Python-list mailing list