python字符串报错。
迷茫
迷茫 2017-04-18 10:06:30
[Python讨论组]

以下为报错代码:

def get_point_id(point_type, id):#id为float或者int

if not id:
    return None
#try:
if True:
    str_id = str(int(id))
    print isinstance(str_id,str)
    if point_type == 'alarm':
        return str_id.rjust(3,'0')//报错。
        

控制台报错为 :
File "b2_insert_standard_template_signals.py", line 118, in get_point_id

return str(str_id).rjust(3,'0')

TypeError: must be char, not unicode

求解决。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(1)
怪我咯

你的文件中是不是加了

from __future__ import unicode_literals

两种解决办法:

1.

str_id.rjust(3, b'0')

2.

str_id = unicode(id)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号