[issue9506] sqlite3 mogrify - return query string
New submission from Kurt Schwehr schw...@ccom.unh.edu: Psycopg2 has a mogrify method on the cursor that returns the string that would be sent to the database for an execute. Any chance that could be added to pysqlite? It's definitely helpful for debugging and is a fantastic tool when teaching people databases. -- components: Extension Modules messages: 112790 nosy: goatbar priority: normal severity: normal status: open title: sqlite3 mogrify - return query string type: feature request versions: Python 2.7, Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9506 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Pulling arrays from database for plotting
Hi all, What's the best way to pull arrays from a database for plotting? Right now, this is what I do, but can it be done simpler / more efficiently? ipython -pylab import sqlite3 cx = sqlite3.connect('20080407.decimated.db3') a = array( [tuple(row) for row in cx.execute('SELECT cg_offset, delta_t_sec FROM bs_time WHERE recvr=2;')] ) x = a[:,0] y = a[:,1] plot(x,y) However, if I try to plot it directly using transpose, it hangs: import sqlite3 cx = sqlite3.connect('20080407.decimated.db3') plot(array( [tuple(row) for row in cx.execute('SELECT cg_offset, delta_t_sec FROM bs_time WHERE recvr=2;')] ).transpose()) It is that plot just doesn't know what to do with a 2D array? Then I tried this and it works, but is long and confusing to the uninitiated. plot(*array( [tuple(row) for row in cx.execute('SELECT cg_offset, delta_t_sec FROM bs_time WHERE recvr=2;')] ).T) In [4]: a Out[4]: array([[ 2.4000e+01, 0.e+00], [ 2.5000e+01, -1.e+00], [ 3.4000e+01, 0.e+00], ..., [ 8.6384e+04, 2.e+01], [ 8.6394e+04, 2.e+01], [ 8.6404e+04, 2.e+01]]) In [5]: a.transpose() Out[5]: array([[ 2.4000e+01, 2.5000e+01, 3.4000e+01, ..., 8.6384e+04, 8.6394e+04, 8.6404e+04], [ 0.e+00, -1.e+00, 0.e+00, ..., 2.e+01, 2.e+01, 2.e+01]]) -- http://mail.python.org/mailman/listinfo/python-list
A superclass using a child classes' methods
I'm trying to build an OO system for encoding and decoding datapackets. I'd like the parent class to have an encode function that uses each of the child classes' packing methods. It appears that this works for attributes of children accessed by the parent, but not for methods. Is that right? For attributes I found this example, where the alphabet attribute is set in the child, but used in the parent. http://www.pasteur.fr/formation/infobio/python/ch19s04.html Should I just set an attribute in the child class and then call the super's functionality making is pull the data from the attribute? Thanks, -kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: A superclass using a child classes' methods
Jean-Michel, Thanks for the excellent response setting me straight. Now to figure out what dumb thing I did to make my code not work... -kurt On Jun 24, 12:23 pm, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Kurt Schwehr wrote: I'm trying to build an OO system for encoding and decoding datapackets. I'd like the parent class to have an encode function that uses each of the child classes' packing methods. It appears that this works for attributes of children accessed by the parent, but not for methods. [clear example of it working] Declaring the foo method at the Parent level is not required. But it's a good practice: explicit implicit and it helps to write proper documentation. Jean-Michel -- http://mail.python.org/mailman/listinfo/python-list
pysqlite2 fetching from select different than pysqlite?
Hi All, I have some old pysqlite 1.x code that uses a pattern like this: cu.execute('SELECT weight FROM weights WHERE samplename=foo) row = cu.fetchone() weight=row['weight'] It seems like lookups by name are no longer supported in pysqlite2. Is that true? And if not, and I want to do a SELECT * FROM table and go through name by name, how can I do this? Hopefully this is not a FAQ somewhere that I've overlooked! Thanks! -kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite2 fetching from select different than pysqlite?
Thanks Tim! That works well. As a followup, is there a standard compliant way to ask what fields are in the table? -kurt Tim Golden wrote: | I have some old pysqlite 1.x code that uses a pattern like this: | | cu.execute('SELECT weight FROM weights WHERE samplename=foo) | row = cu.fetchone() | weight=row['weight'] | http://initd.org/pub/software/pysqlite/doc/usage-guide.html#accessing-co lumns-by-name-instead-of-by-index you have to specify a .row_factory before running the select TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite2 fetching from select different than pysqlite?
Perfect. Thanks much! -kurt python from pysqlite2 import dbapi2 as sqlite db = sqlite.connect (:memory:) db.row_factory = sqlite.Row db.execute (CREATE TABLE x (i INTEGER, code VARCHAR (10), name VARCHAR (60))) for row in db.execute (PRAGMA TABLE_INFO ('x')): print row['name'], row['type'] /python -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite2 fetching from select different than pysqlite?
Dennis Lee Bieber wrote: cursor.description -- after an .execute() has selected data. Thanks Dennis, The desciription works, but gives some funky results, but with python it is not a big deal. cu.description (('activity_id', None, None, None, None, None, None), ('case_id', None, None, None, None, None, None), ('incident_dt', None, None, None, None, None, None), ('activity_type', None, None, None, None, None, None), ('vessel_id', None, None, None, None, None, None), ('waterway_name', None, None, None, None, None, None), ('event_type', None, None, None, None, None, None), ('event_class', None, None, None, None, None, None), ('event_subclass', None, None, None, None, None, None), ('activity_role', None, None, None, None, None, None), ('damage_status', None, None, None, None, None, None), ('latitude', None, None, None, None, None, None), ('longitude', None, None, None, None, None, None)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting socket connection failure
Hi Dieter, Thanks for the feedback. Were you also using mac osx? I am wondering at what level this bug is occuring. -kurt Dieter Maurer wrote: [EMAIL PROTECTED] writes on 10 Jul 2006 08:42:11 -0700: I've tried to RTFM this and am having no luck.First off, I am using Mac OSX 10.4.7 with python 2.4.2 from fink. I am trying to connect to a server that should be rejecting connections and I was surprised when it did not throw an exception or do something otherwise equally nasty. It just connects and never returns any data. First, the proof that something is there and rejecting the connection (or is it that this thing actually accepts the connection and then drops it?)... telnet localhost 31414 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Connection closed by foreign host. What you see here is that the connection was opened successfully (the connect succeeded) and then closed again. ... In [1]: import socket, select In [2]: remote = socket.socket(socket.AF_INET,socket.SOCK_STREAM) In [3]: remote.connect(('localhost',31414)) In [4]: remote.recv(200) Out[4]: '' The means, that you see the same in Python: recv returning an empty string indicates that the connection was closed. In [5]: r,w,e=select.select([remote],[remote],[remote],1) In [6]: print r,w,e [socket._socketobject object at 0x7e48d0] [socket._socketobject object at 0x7e48d0] [] I have seen something similar recently: I can write (send to be precise) to a socket closed by the foreign partner without error (but of course, the written data does not arrive at the remote side). Only the second send raises an exception. I expect this is a TCP bug. -- Dieter -- http://mail.python.org/mailman/listinfo/python-list
Detecting socket connection failure
Hi All, I've tried to RTFM this and am having no luck.First off, I am using Mac OSX 10.4.7 with python 2.4.2 from fink. I am trying to connect to a server that should be rejecting connections and I was surprised when it did not throw an exception or do something otherwise equally nasty. It just connects and never returns any data. First, the proof that something is there and rejecting the connection (or is it that this thing actually accepts the connection and then drops it?)... telnet localhost 31414 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Connection closed by foreign host. Now if I fire up ipython and try to connect... In [1]: import socket, select In [2]: remote = socket.socket(socket.AF_INET,socket.SOCK_STREAM) In [3]: remote.connect(('localhost',31414)) In [4]: remote.recv(200) Out[4]: '' In [5]: r,w,e=select.select([remote],[remote],[remote],1) In [6]: print r,w,e [socket._socketobject object at 0x7e48d0] [socket._socketobject object at 0x7e48d0] [] In [7]: remote.recv(200) Out[7]: '' So it looks like it will for ever say that it is ready for read and write, but really is not. How do I detect this case? The recv may really not have any data for a long time, so a recv of no bytes is not a way to test the connection status. This is probably a FAQ, but I can't figure it out. Thanks!! -kurt -- http://mail.python.org/mailman/listinfo/python-list
+= append class operator
Hi All, This is probably a FAQ, but is there an operator mapping for += for classes? Or does a += b get converted to a = a + b? I would like to make this operator faster for the BitVector class, but I don't see += in http://docs.python.org/lib/operator-map.html I could always create an append method, but += is nice and concise. Thanks, -kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: += append class operator
Awesome. Thanks! -kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: packaging question - documentation
Sorry about not being clear. I have been downloading quite a few packages for examples, but have not found a good example of man page building from optparse. seismic-py - setup.py - seismic - __init.py__ - bulk of the code *.py - scripts - programs that go in bin/the users executable path (no .py extension) -- http://mail.python.org/mailman/listinfo/python-list
packaging question - documentation
Hi All, I am rearranging the layout of one of my python projects so that it more closely conforms to how most python projects seem to work. I now have a structure like this: seismic-py - setup.py - seismic - bulk of the code - scripts - programs that go in bin I am using OptionParser, help2man, groff and man2html to provide man pages. Everything was sitting in the top level directory, so it was clear where to put these, but where do I put the foo.help2man files that contain extra text for the man pages? If I put it in scripts, that is pretty easy to cope with, but I was thinking about a docs directory, but then the build process might be more difficult. Or should I be putting in another string in each executable that contains this extra man page info? Then it would show up in epydoc as well. Maybe something like __help2man__ = ''' [AUTHOR] Kurt Schwehr [SEE ALSO] segysql.py [DESCRIPTION] .PP The --coord-unit option is designed to allow use of databases that exclude the CoordUnit field. This field is probably the same for all traces in the majority of SEGY data files, so most segy-py drivers will want to exclude coordunit from the short list (see segysql.py). The values are taken from page 14 of the SEG-Y Rev 1 specification -1 = Follow field 89-90 of the trace header 1 = Length (meters or feet) [NOT supported] 2 = Seconds of arc 3 = Degrees, minutes, seconds (DMS) [NOT SUPPORTED] ''' I am still in the middle of shuffling the tree about, but it is available here... https://cowfish.unh.edu/projects/seismic-py/ Any thoughts would be greatly appreciated! I am still trying to understand the best practices for python packaging. Thanks! -kurt -- http://mail.python.org/mailman/listinfo/python-list
Building files within a package
Hi All, I am creating a python package that contains a whole pile of functions that build lookup tables. Since these lookup tables will not be changing, I would like to have setup.py create a lut_static.py fie from the lookup table code (lut.py). What is the best way to do this so that when I install the package the static tables get build? It basically looks like this foo-py-0.1 setup.py foo lut.py lut_static.py - want to generate this from lut.py For development, it is easy enough for me to have a Makefile in foo that creates lut_static.py when ever lut.py is changed, but I would like to make setup.py handle this so if someone tweaks the lut.py and reinstalls it, they don't have to know about foo/Makefile Thanks! -kurt -- http://mail.python.org/mailman/listinfo/python-list
passing artibrary strings into a database
Hi All, I was wondering if there is a helper library out there that will nicely encode artibrary text so that I can put in into a TEXT field in a database and then retrieve it without getting into trouble with ',,new lines or other such things that would foul the sql insert call and or be a security hazard? This feels like a newbee type question, but I haven't found anything with a quick search. Thanks, -kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: passing artibrary strings into a database
Thanks! Looks like I need to get a newer version of pysqlite into the fink package tree since pysqlite 1.0.1 does not appear support that -- http://mail.python.org/mailman/listinfo/python-list
Math markup in code documentation?
Done any one have a way (and examples) of how to do math markups in the docstrings of function and class definitions such that the equations get typeset in the generated html documentation? I'll take any markup system that'll do the job... MathML or LaTeX possible? I'd like to start doing a better job of documenting the equations and units being used in pmag-py (http://schwehr.org/software/pmag) for processing paleomagnetic data. AND on the longest of long shots... anyone have any opensource python for matching bulk composition to minerals? Nah, I thought not. Thanks! -kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: Math markup in code documentation?
Awesome!!! When did doxygen start supporting python? I was really into doxygen last year, but stopped using it when I started doing a lot of coding in python. Thanks -kurt -- http://mail.python.org/mailman/listinfo/python-list
keeping unit test info out of pydoc -w?
Hi All, Is there an easy way to keep the unittest stuff out of the documentation that gets generated by pydoc -w? I just want to exclude the Methods inherited from unittest.TestCase: section. Thanks! -kurt -- http://mail.python.org/mailman/listinfo/python-list
latex/bibtex python paper?
Hi All, Does anyone have a good template that I might use for writing a python paper in latex/bibtex? I've got the paper mostly done, but am having issues with the references. I am definitely not an expert at latex/bibtex. Right now, I have references defined like this: @article{imp, title = {imp -- Access the import internals}, journal = http://www.python.org/doc/current/lib/module-imp.html;, author = {Python Software Foundation}, year = {2005} } When I cite these, I get something like this (Foundation[2005]). Is anyone willing to offer up a tarball of a complete paper with sty and bst that would make for a nice python paper? Thanks! -kurt http://schwehr.org/software/segy-py -- http://mail.python.org/mailman/listinfo/python-list