<https://lh3.googleusercontent.com/-mUGluzqE6f8/Vh4LDTLbYRI/AAAAAAAABgk/URjq7MDrjiA/s1600/error-cajaImp.jpg> 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 <javascript:>> > 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 <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.