for borehole in alldata: for attr in sorted(filter(lambda a: not a.startswith('_'), dir(borehole))): print attr, getattr(borehole, attr)
could do the trick On Wed, Aug 29, 2012 at 1:24 PM, Gery . <gameji...@hotmail.com> wrote: > > thanks Robert, using your suggestion I get: > > ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', > '__hash__', '__init__', '__module__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', > '_sa_class_manager', '_sa_instance_state', u'comments', u'core_rec_m', > u'fid', u'geom', u'h_f_mwm2', u'id', u'latitude', u'longitude', > u'max_pen_m', u'source', u'station', u'survey', u't_g_ckm1', u'type', > u'w_depth_m'] > > so you were right, but one question, when I use: > > > ************************************************************************************************************************************************** > # starting with ORM: declarative base class [catalog of classes mapped to > database tables relative to this base] > mybase = declarative_base(metadata=mymetadata) > > # defining classes to be mapped > class Boreholes(mybase): > __tablename__ = 'boreholes_point_wgs84' > __table_args__ = {'autoload':True} > > def __init__ (self, id, fid, longitude, latitude, w_depth_m, > station, type, survey, source, max_pen_m, core_rec_m, t_g_ckm1, h_f_mwm2, > comments): > self.id = id > self.fid = fid > self.longitude = longitude > self.latitude = latitude > self.w_depth_m = w_depth_m > self.station = station > self.type = type > self.survey = survey > self.source = source > self.max_pen_m = max_pen_m > self.core_rec_m = core_rec_m > self.t_g_ckm1 = t_g_ckm1 > self.h_f_mwm2 = h_f_mwm2 > self.comments = comments > > def __repr__ (self): > return "Boreholes(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, > %s, %s, %s, %s)" % (self.id, self.fid, self.longitude, self.latitude, > self.w_depth_m, self.station, self.type, self.survey, self.source, > self.max_pen_m, self.core_rec_m, self.t_g_ckm1, self.h_f_mwm2, > self.comments) > ************************************************************************************************************************************************** > > whit the same print.alldata I can output all the rows, but in this way I > don't know how to make the mapper(Boreholes, boreholes) I used in the first > place. Is it possible to print all the rows with my original code? > > 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. > > >> Date: Wed, 29 Aug 2012 13:05:18 +0200 >> Subject: Re: [sqlalchemy] __main__ error >> From: xrotw...@googlemail.com >> To: sqlalchemy@googlegroups.com >> >> doesn't look like an error to me. It's just the result of your >> >> print alldata >> >> call. It depends on Postgis which attributes are available on the >> Borehole instances, but you could use >> >> print dir(alldata[0]) >> >> to get an idea about what is available. >> >> On Wed, Aug 29, 2012 at 12:37 PM, 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 >> > >> > >> > >> > >> > >> > >> > >> > >> > __________________________________________________________________________________________ >> > 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. >> > >> > -- >> > 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. >> > > -- > 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.