£登录python SQLAlchemy查询

2024-06-16 12:56:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图以以下方式将字符串注入到查询中:

value = '£'
query = """select * from table where condition = '{0}';""".format(value)

问题是这种格式的结果是:

select * from table where condition = '\xc2\xa3';

因为我将在sqlalchemy中使用这个查询,所以我需要编码的字符显示为实际的双关符号。你知道吗

有什么办法让这个问题看起来像这样吗?地址:

select * from table where condition = '£';

我正在使用Postgres3.5和Python2.7.6

如果我尝试以下方法:

'\xc2\xa3'.decode('utf-8')

结果是:

u'\xa3'


Tags: 字符串fromformat编码sqlalchemyvalue格式方式