【发布时间】:2017-11-21 04:47:27
【问题描述】:
def get_point_id(point_type, id):#id is str,like:"001",“1001.0”
if not id:
return None
if True:
str_id = str(int(id))
if point_type == 'alarm':
return str_id.rjust(3,'0')# error
当我运行它时,控制台显示:
文件“b2_insert_standard_template_signals.py”,第 118 行,在 get_point_id 中
return str_id.rjust(3,'0') TypeError: 必须是 char,而不是 unicode
str_id 是一个 str,不是 unicode,我不知道为什么。这个 py 文件已经声明了 # -- coding: utf-8 --
我的 python 版本是 2.7.3。请帮帮我。
【问题讨论】:
-
@rai_zhang 在 python 2.7.12 中运行您的代码。工作正常。没有错误。你能说明你是如何调用
get_point_id方法的吗? -
我只想格式化 id 。像这样: value=get_point_id(point_type, id), filnal ,vale会存储一个dict的值
标签: python-2.7