Thanks Simon, that's the way, it works well, but is it possible to output all the tables without specifying every column?
Thanks, Gery __________________________________________________________________________________________ Piensa en el medio ambiente - mantenlo en la pantalla. NO lo imprimas si NO es necesario. Think green - keep it on the screen. Do NOT print if it is NOT necessary. Denken Sie an die Umwelt - bewahren Sie es auf dem Bildschirm. Drucken Sie NICHT, wenn es NICHT notwendig ist. > From: si...@simonking.org.uk > Date: Wed, 29 Aug 2012 12:19:42 +0100 > Subject: Re: [sqlalchemy] __main__ error > To: sqlalchemy@googlegroups.com > > On Wed, Aug 29, 2012 at 11:37 AM, Gery . <gameji...@hotmail.com> wrote: > > > > Hello, > > > > I'm quite new in SA and I'm having some problems with a script. After > > running the script, I'm getting this error: > > > > [<__main__.Boreholes object at 0xb7a2958c>, <__main__.Boreholes object at > > 0xb7a2962c>, <__main__.Boreholes object at 0xb7a2966c>, <__main__.Boreholes > > object at 0xb7a296cc>, <__main__.Boreholes object at 0xb7a2972c>, > > <__main__.Boreholes object at 0xb7a2978c>, <__main__.Boreholes object at > > 0xb7a297ec>, <__main__.Boreholes object at 0xb7a2984c>, <__main__.Boreholes > > object at 0xb7a298ac>, <__main__.Boreholes object at 0xb7a2990c>, > > <__main__.Boreholes object at 0xb7a2996c>, <__main__.Boreholes object at > > 0xb7a299cc>, <__main__.Boreholes object at 0xb7a29a2c>, <__main__.Boreholes > > object at 0xb7a29a8c>, <__main__.Boreholes object at 0xb7a29aec>, > > <__main__.Boreholes object at 0xb7a29b4c>, <__main__.Boreholes object at > > 0xb7a29bac>, <__main__.Boreholes object at 0xb7a29c2c>, <__main__.Boreholes > > object at 0xb7a29cac>, <__main__.Boreholes object at 0xb7a29d2c>, > > <__main__.Boreholes object at 0xb7a29dac>, <__main__.Boreholes object at > > 0xb7a29e2c>, <__main__.Boreholes object at 0xb7a29eac>, <__main__.Boreholes > > object at 0xb7a29f2c>, <__main__.Boreholes object at 0xb7a29fac>, > > <__main__.Boreholes object at 0xb7a3504c>, <__main__.Boreholes object at > > 0xb7a350cc>, <__main__.Boreholes object at 0xb7a3514c>, <__main__.Boreholes > > object at 0xb7a351cc>, <__main__.Boreholes object at 0xb7a3524c>, > > <__main__.Boreholes object at 0xb7a352cc>, <__main__.Boreholes object at > > 0xb7a3534c>, <__main__.Boreholes object at 0xb7a353cc>, <__main__.Boreholes > > object at 0xb7a3544c>, <__main__.Boreholes object at 0xb7a354cc>, > > <__main__.Boreholes object at 0xb7a3554c>, <__main__.Boreholes object at > > 0xb7a355cc>, <__main__.Boreholes object at 0xb7a3564c>, <__main__.Boreholes > > object at 0xb7a356cc>, <__main__.Boreholes object at 0xb7a3574c>, > > <__main__.Boreholes object at 0xb7a357cc>, <__main__.Boreholes object at > > 0xb7a3584c>, <__main__.Boreholes object at 0xb7a358cc>, <__main__.Boreholes > > object at 0xb7a3594c>, <__main__.Boreholes object at 0xb7a359cc>, > > <__main__.Boreholes object at 0xb7a35a4c>, <__main__.Boreholes object at > > 0xb7a35acc>, <__main__.Boreholes object at 0xb7a35b4c>, <__main__.Boreholes > > object at 0xb7a35bcc>, <__main__.Boreholes object at 0xb7a35c4c>, > > <__main__.Boreholes object at 0xb7a35ccc>] > > > > > > the script is here: > > > > ************************************************************************************************************* > > > > # import things to be used > > from sqlalchemy import create_engine, MetaData, Table > > from sqlalchemy.orm import mapper, sessionmaker > > > > # connecting to database engine > > myengine = create_engine('postgresql://postgres:pass@localhost:5432/mop', > > echo=False) > > > > # MetaData: describing the database schema > > mymetadata = MetaData(myengine) > > > > # load existing tables in postgis database > > boreholes = Table('boreholes_point_wgs84', mymetadata, autoload=True) > > > > # defining empty classes to be mapped to existing tables > > class Boreholes(object): > > pass > > > > # mapping empty classes to existing tables [ie. ORM] > > Boreholesmapper = mapper(Boreholes, boreholes) > > > > # session operations [finding data, adding data, modifying data and deleting > > data] > > Session = sessionmaker(bind=myengine) > > mysession = Session() > > > > # queries > > alldata = mysession.query(Boreholes).all() > > print alldata > > > > ************************************************************************************************************* > > > > I'm working with python2.4 and SA 0.7.8 in rhel5 (32-bit). > > > > Any hint is appreciated, > > > > Best regards, > > > > Gery > > > > That's not an error - that is a list of instances of the Borehole > class, which is what you get back from Query.all(). > > The columns in your boreholes_point_wgs84 become properties of those > instances. So for example if the table has "name", "latitude" and > "longitude" columns, you would be able to change your last 2 lines to > say something like: > > for borehole in mysession.query(Boreholes).all(): > print borehole.name, borehole.latitude, borehole.longitude > > Hope that helps, > > Simon > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.