2006年03月04日 星期六 20:57
打印的结果凡是中文的都乱码了,是什么原因造成的?解决方案? #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
2006年03月05日 星期日 13:51
你这样打印是会这样的,因为编码问题啊,你如果直接打印你需要处理下编码。 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
2006年03月05日 星期日 15:17
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
Zeuux © 2025
京ICP备05028076号