SQLAlchemy打印(def __str __(self):) - UnicodeDecodeError

时间:2016-10-04 16:28:23

标签: python

导致问题的我的班级定义:

int a=1,b=1,c=1;
boolean b = a==b&&b==c;//line2: (a==b)&&(b==c) 
 /*   In line2 code would not run from left to right. 
First a==b is evaluated then b==c and then && operator.*/

我的引擎:

class Auction(Base):
    __tablename__ = 'auctions'

    id = Column(Integer, primary_key=True)    
    owner = Column(String, nullable=False)

    # a lot of other not important attributes 

    def __str__(self):
        return u"<Auction(id={0}, owner={1})>".format(self.id, self.owner)

    def __repr__(self):
        return self.__str__()

    def __unicode__(self):
        return self.__str__()

有问题的代码:

engine = create_engine('sqlite:///somepath', encoding='utf8', echo=True)

打印得很好,除非使用了unicode char(s = Session() #using the engine above for a in s.query(Auction).all(): print a .owner)。

错误:

.owner_realm

我也试过UnicodeEncodeError: 'ascii' codec can't encode character u'\xf8' in position 70: ordinal not in range(128) ,但这也没有帮助。同样,将print unicode(a)解析为self.owner也无济于事。

我确实填充它 - 我使用unicode(self.owner)来填充拍卖实例,问题仅在于打印。

0 个答案:

没有答案