Python论坛  - 讨论区

标题:[python-chinese] mysqldb fetchone方法返回的元组中的中文数据乱码问题

2006年03月04日 星期六 20:57

=?ISO-2022-JP?B?GyRCcjJDaRsoQg==?= weizhong2004 at gmail.com
Sat Mar 4 20:57:43 HKT 2006

打印的结果凡是中文的都乱码了,是什么原因造成的?解决方案?

#coding=gb2312
import MySQLdb as mydb
db=mydb.connect(host='localhost',user='root',passwd='',db='water')
cur=db.cursor()
cur.execute("select site_name,site_group from sites limit 10");
while 1:
    a=cur.fetchone()
    if a:
        for x in a:
            print x,
    else:break

--
开飞机的舒克
http://www.lvye.org/shuke
msn:weizhong at netease.com
my-tag:IM我也在用.但一般只对熟悉的人开.这东西太占时间.相比还是maillist好.让自已思考,让别人思考,让更多人参与.--limodou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060304/083344a3/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月05日 星期日 13:51

唐晓平 xiaoping.tang at gmail.com
Sun Mar 5 13:51:54 HKT 2006

你这样打印是会这样的,因为编码问题啊,你如果直接打印你需要处理下编码。

On 3/4/06, 魏忠 <weizhong2004 at gmail.com> wrote:
>
> 打印的结果凡是中文的都乱码了,是什么原因造成的?解决方案?
>
> #coding=gb2312
> import MySQLdb as mydb
> db=mydb.connect(host='localhost',user='root',passwd='',db='water')
> cur=db.cursor()
> cur.execute("select site_name,site_group from sites limit 10");
> while 1:
>     a=cur.fetchone()
>     if a:
>         for x in a:
>             print x,
>     else:break
>
> --
> 开飞机的舒克
> http://www.lvye.org/shuke
> msn:weizhong at netease.com
> my-tag:IM我也在用.但一般只对熟悉的人开.这东西太占时间.相比还是maillist好.让自已思考,让别人思考,让更多人参与.--limodou
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060305/eddb9989/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月05日 星期日 15:17

fanlix fanlix at gmail.com
Sun Mar 5 15:17:04 HKT 2006

print x.encode("gb2312")
#x should be in unicode form
# encode to "gb2312" ,only to show out.


2006/3/5, 唐晓平 <xiaoping.tang at gmail.com>:
>
> 你这样打印是会这样的,因为编码问题啊,你如果直接打印你需要处理下编码。
>
>  On 3/4/06, 魏忠 <weizhong2004 at gmail.com> wrote:
>
> >  打印的结果凡是中文的都乱码了,是什么原因造成的?解决方案?
> >
> > #coding=gb2312
> > import MySQLdb as mydb
> > db=mydb.connect(host='localhost',user='root',passwd='',db='water')
> > cur=db.cursor()
> > cur.execute("select site_name,site_group from sites limit 10");
> > while 1:
> >     a=cur.fetchone()
> >     if a:
> >         for x in a:
> >             print x,
> >     else:break
> >
> > --
> > 开飞机的舒克
> > http://www.lvye.org/shuke
> > msn:weizhong at netease.com
> > my-tag:IM我也在用.但一般只对熟悉的人开.这东西太占时间.相比还是maillist好.让自已思考,让别人思考,让更多人参与.--limodou
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060305/3624da1f/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号