我有一个用排序规则UTF8定义的MySQL数据库。表“clientes”及其所有列都被指定为UTF8。在DROP TABLE IF EXISTS `clientes`;
CREATE TABLE IF NOT EXISTS `clientes` (
`ID` varchar(35) NOT NULL DEFAULT '',
`nombre` varchar(255) NOT NULL DEFAULT '',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `clientes` (`ID`, `nombre`) VALUES
('111', 'María Español Marqués'),
('222', 'Paulo Conceiçao'));
使用MySQL客户端(在终端中,phpmyadmin…)进行查询时,会显示以下字符:
^{pr2}$
现在,我用SQLAlchemy创建类:#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy import Column, Date, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
engine = create_engine('mysql://root:toor@localhost')
engine.execute("USE nTal")
Base = declarative_base()
class Cliente(Base):
__tablename__ = "clientes"
ID = Column(String(35), primary_key=True)
nombre = Column(String(255))
def __init__(self, nombre):
""""""
self.nombre = nombre
engine.dispose()
当我用SQLAlchemy运行一个查询时,我得到带有重音符号的奇怪字符,西班牙语和葡萄牙语simbol不可见。在res = session.query(Cliente).all()
for cliente in res:
print cliente.ID + ", " + cliente.nombre
111, Mar�a Espa�ol Marqu�s
222, Paulo Concei�ao
当然,我搜索了很多关于编码和解码的内容,但是我发现的最多的是错误,而不是错误的显示。在
提前谢谢。在