[Numpy-discussion] Outputting arrays.

Matt Knox mattknox.ca@gmail....
Wed May 21 16:40:01 CDT 2008


> 1. Is there a module or other code to write arrays to databases (they want
access databases)?

There are three python odbc modules (mxODBC, ceODBC, pyodbc), all of which
should allow you to connect to access databases. I've played around with all
three and my personal favourite is ceODBC (which is probably the least well
known too).

Here is a quick summary of the three:

mxODBC:
 pros: fast, reliable
 cons: not free, uses mx.DateTime objects for dates instead of standard python
datetime

pyodbc:
 pros: free
 cons: last time I used it, it was quite buggy. It's slow for some things. Uses
a wierd custom "row" object instead of standard tuples in the results.

ceODBC:
 pros: free, fast, reliable
 cons: doesn't seem to be very actively developed, but the existing code is very
good

Now, as for how you use these to store arrays in a db...  I have a brief
tutorial on the timeseries wiki (http://scipy.org/scipy/scikits/wiki/TimeSeries)
for working with timeseries objects and relational databases. The same general
approach works for standard arrays. The key is to make use of the executemany
method in the database modules for inserting, and use the python zip function a
lot and the tolist method of arrays. Note that if you are inserting a one
dimensional array, you'll need to do "myarray.reshape((myarray.size,
1)).tolist()" to pass it as a parameter to executemany (so you get a list of
"rows" instead of just a single list of numbers).

If you need more detail, let me know and I can make a fuller example.

- Matt





More information about the Numpy-discussion mailing list