python 关于str和unicode

luoryan 2014-01-13 07:12:44
有以下两行数据
1 u'\u5176\u4ed6':6L
2 u'\u5176\u4ed6':0.0

我是想转化成中文输出,并且数值能够加减
for line in sys.stdin:
fields = line.strip().split("\t")
info = fields[1].split(":")
print fields[0],info[0],info[1]

这样输出还是原样输出,type(info[0])和type(info[1])都是<type 'str'>
请问为什么不是<type 'unicode'>和<type 'long'>
如果要输出中文要怎么改?
...全文
170 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
angel_su 2014-01-15
  • 打赏
  • 举报
回复
一般输入是8bit字串,直接输入中文再按需按编码转换成unicode字串,需要数字类型用int()或float()转换...

37,718

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧