MySQL, Python, NumPy and formatted read

John Nagle nagle at animats.com
Wed May 26 15:53:30 EDT 2010


Ian Hoffman wrote:
> Hello,
> 
> I'm having significant Python difficulties (and I'm new to Python).
> I'm trying to read BLOB ASCII (numerical) data from a MySQL database
> using MySQLdb in a formatted fashion.  The BLOB data is a sequence of
> numbers separated by newlines (\n), like this:
> 5
> 6
> 10
> 45
> etc.

    Note that a BLOB is not ASCII.  If you're storing ASCII text, use type
TEXT in SQL, not type BLOB.  Don't lie to the database.  It doesn't like that.
And if you're going to store numbers, store numbers, not text.  SQL has
the usual integer and floating point types.

    When you read a BLOB from MySQLdb, you do not get a string.  You get
an object of type "bytes".  This is not a Python string.  Python strings
can be ASCII or Unicode in Python 2.x, and in 3.x, are always Unicode.

					John Nagle



More information about the Python-list mailing list