在使用python-rrdtool进行rrd的创建时
产生
TypeError: argument 0 must be string
的错误
始终搞不明白是为什么,每个参数都已经检查了是字符串
但是总是出这个错误
后来在rrdtool的forum上偶尔看到,参数不可以是unicode
才想起来,我的参数确实是unicode的
解决方法很简单,使用参数时,encode一下即可。
注:python中
>>> type(u'server')
<type 'unicode'>
>>> type('server')
<type 'str'>
>>> u'server' == 'server'
True
>>> u'中文' == '中文'
__main__:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
False