Yes this is the result of printing:

c = se.query(Caja).get(1)
c.__dict__
{'Entidad': u'Eprueba', '_sa_instance_state': 
<sqlalchemy.orm.state.InstanceState object at 0x03027570>, 'Salida': 10.0, 
'Fecha': datetime.date(2015, 10, 12), 'id_Conceptos': 1, 'Grupo': u'grp', 
'id': 1, 'Entrada': 50.0}

type(c)
<class 'modeloCaja.Caja'>

type(c).__dict__
dict_proxy({'Entidad': <sqlalchemy.orm.attributes.InstrumentedAttribute 
object at 0x02FE8FD0>, '__module__': 'modeloCaja', '_sa_class_manager': 
<ClassManager of <class 'modeloCaja.Caja'> at 2fc7ae0>, 'Salida': 
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x02FFE270>, 
'Fecha': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 
0x02FFE090>, 'id_Conceptos': 
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x02FE8F30>, 
'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object at 
0x02FE8E90>, '__repr__': <function __repr__ at 0x02FDE9F0>, '__dict__': 
<attribute '__dict__' of 'Caja' objects>, 'Grupo': 
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x02FFE130>, 
'__weakref__': <attribute '__weakref__' of 'Caja' objects>, '__doc__': 
None, '__init__': <function __init__ at 0x02FDEC70>, 'Entrada': 
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x02FFE1D0>})

sys.modules[type(c).__module__]
<module 'modeloCaja' from 'modeloCaja.pyc'>

My sa.vesion is *0.7.10*
Can it be that the version is out of date?


I appreciate all your efforts to resolve.
------------------------

El miércoles, 14 de octubre de 2015, 21:52:05 (UTC+2), Simon King escribió:
>
> Works for me: 
>
> Python 2.7.10 (default, Aug 22 2015, 20:33:39) 
> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwin 
> Type "help", "copyright", "credits" or "license" for more information. 
> >>> from modelosCaja import * 
> >>> c = se.query(Caja).get(1) 
> >>> c 
> <Caja('1', Cond. None Ent:Eprueba Fch:None Grup:grp', Ent: 50' Sal: 10 
> Imp:40.00)> 
> >>> c.imp 
> 40.0 
> >>> sa.__version__ 
> ‘1.0.8' 
>
>
> Have you tried printing out the things I suggested earlier? 
>
> Simon 
>
> > On 14 Oct 2015, at 08:58, Cecilio Ruiz <ceci...@gmail.com <javascript:>> 
> wrote: 
> > 
> > 
> > 
> > Inimport sqlalchemy as sa 
> > from sqlalchemy.orm import mapper, sessionmaker 
> > from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method 
> > from sqlalchemy.ext.declarative import declarative_base 
> > 
> > db_engine = sa.create_engine('sqlite:///caja.sqlite') 
> > metadata = sa.MetaData() 
> > Base = declarative_base() 
> > 
> > # Table definition - Conceptos 
> > # 
> > Conceptos_table = sa.Table("Conceptos", metadata, 
> >     sa.Column('id', sa.Integer, nullable=True, autoincrement=True, 
> primary_key=True), 
> >     sa.Column('Nombre', sa.String)) 
> > 
> > # Table definition - Caja 
> > # 
> > Caja_table = sa.Table("Caja", metadata, 
> >     sa.Column('id', sa.Integer, nullable=True, autoincrement=True, 
> primary_key=True), 
> >     sa.Column('id_Conceptos', sa.Integer, sa.ForeignKey("Conceptos.id"), 
> nullable=True), 
> >     sa.Column('Entidad', sa.String, nullable=True), 
> >     sa.Column('Fecha', sa.Date, nullable=True), 
> >     sa.Column('Grupo', sa.Integer, nullable=True), 
> >     sa.Column('Entrada', sa.Float, default=0, nullable=True), 
> >     sa.Column('Salida', sa.Float, default=0, nullable=True)) 
> > 
> > 
> > # Mapping Objects 
> > class Conceptos(object): 
> >     def __init__(self, Nombre): 
> >         #self.id = id 
> >         self.Nombre = Nombre 
> > 
> >     def __repr__(self): 
> >         return "<Conceptos('%s', '%s')>" % (self.id, self.Nombre) 
> > 
> > class Caja(object): 
> >     def __init__(self, id_Conceptos, Entidad, Fecha, Grupo, Entrada, 
> Salida):         
> >         self.id_Conceptos = id_Conceptos 
> >         self.Entidad = Entidad 
> >         self.Fecha = Fecha 
> >         self.Grupo = Grupo 
> >         self.Entrada = Entrada 
> >         self.Salida = Salida 
> > 
> >     @hybrid_property 
> >     def imp(self): 
> >         return float(self.Entrada - self.Salida) 
> >         
> >     def __repr__(self): 
> >         return "<Caja('%s', Cond. %s Ent:%s Fch:%s Grup:%s', Ent: %i' 
> Sal: %i Imp:%.2f)>" % (self.id, self.id_Conceptos, self.Entidad, 
> self.Fecha, self.Grupo, self.Entrada, self.Salida, self.imp) 
> > 
> > 
> > # Declare mappings 
> > mapper(Conceptos, Conceptos_table) 
> > mapper(Caja, Caja_table) 
> > 
> > # Create a session 
> > session = sessionmaker(bind=db_engine) 
> > se = session() 
> > metadata.create_all(db_engine) 
> > 
> > 
> > 
> > This is modelosCaja.py 
> > Now I open the Python in terminal (CMD) 
> > ---------------in python terminal---------------------- 
> > from modeloCaja import * 
> > c = se.query(Caja).imp 
> > >> the herror. 
> > 
> > 
> > 
> > 
> > 
> > El miércoles, 14 de octubre de 2015, 0:05:45 (UTC+2), Simon King 
> escribió: 
> > Do you perhaps have more than one “Caja” class in your application? Try 
> printing out some of the following values: 
> > 
> > your_instance.__dict__ 
> > type(your_instance) 
> > type(your_instance).__dict__ 
> > sys.modules[type(your_instance).__module__] 
> > 
> > Can you drop into pdb at the point where the exception occurs and poke 
> around at the object interactively? 
> > 
> > Otherwise, you’re going to have to send us a complete script that 
> demonstrates the problem. 
> > 
> > Simon 
> > 
> > > On 13 Oct 2015, at 22:37, Cecilio Ruiz <ceci...@gmail.com> wrote: 
> > > 
> > > The error message says: : "AttributeError: 'Caja' object has no 
> attribute 'imp' 
> > > 
> > > Yes, is typo error en email. The imp attibute is lower case. 
> > > 
> > > El martes, 13 de octubre de 2015, 23:01:34 (UTC+2), Simon King 
> escribió: 
> > >   return "<Caja('%s', Cond. %s Ent:%s Fch:%s Grup:%s', Ent: %i' Sal: 
> %i Imp:%.2f)>" % (self.id, self.id_Conceptos, self.Entidad, self.Fecha, 
> self.Grupo, self.Entrada, self.Salida, self.imp) 
> > > > 
> > > 
> > > Can you share the full traceback? Caja.Imp doesn’t exist, but Caja.imp 
> (note lower case “i”) should, so assuming that was a typo in your email, 
> there must be some other problem. 
> > > 
> > > Simon 
> > > 
> > > -- 
> > > You received this message because you are subscribed to the Google 
> Groups "sqlalchemy" group. 
> > > To unsubscribe from this group and stop receiving emails from it, send 
> an email to sqlalchemy+...@googlegroups.com. 
> > > To post to this group, send email to sqlal...@googlegroups.com. 
> > > Visit this group at http://groups.google.com/group/sqlalchemy. 
> > > For more options, visit https://groups.google.com/d/optout. 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "sqlalchemy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to sqlalchemy+...@googlegroups.com <javascript:>. 
> > To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:>. 
> > Visit this group at http://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to