请各位大侠伸出温暖的双手拉我一把,python3中的变化
本帖最后由 paul_26piggy 于 2012-10-15 21:16:33 编辑 python3中的变化
首先是错误,一开始是对于输入的特征字符串分析,然后在添加到列表中出了错
You want to (F)ilter the log or (A)ppend the error lib?Q for quit : a
Please input the Error template you want to append:24798 2010-06-21 02:59:49.839 DeviceAgent Warning DaH248Msg received with error code 5101
Start to append the Error lib
0 24798
1 2010-06-21
2 02:59:49.839
3 DeviceAgent
4 Warning
5 DaH248Msg
6 received
7 with
8 error
9 code
10 5101
The new error template belongs to Module :DeviceAgent
The length of this record is : 11
The log_level :Warning
Please input the index of the str you choose as the key:10
search the current err lib ......
Traceback (most recent call last):
File "C:\Paul\pycode\log_handle_2012\src\log_handle_2012.py", line 346, in <module>
append_result = append_lib(str(err_temp_input))
File "C:\Paul\pycode\log_handle_2012\src\log_handle_2012.py", line 185, in append_lib
if (compare_newobj_w_err_temp_list(new_temp) == True):
File "C:\Paul\pycode\log_handle_2012\src\log_handle_2012.py", line 148, in compare_newobj_w_err_temp_list
if (temp.__cmp__(newobj) == False):
File "C:\Paul\pycode\log_handle_2012\src\log_handle_2012.py", line 54, in __cmp__
if((cmp(self.index, dict.index) == 0)
NameError: global name 'cmp' is not defined
'cmp' 好奇怪,python3没有这个函数了么?
[解决办法]
引自"What's new in python 3.0":
The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported. Use __lt__() for sorting, __eq__() with __hash__(), and other rich comparisons as needed. (If you really need the cmp() functionality, you could use the expression (a > b) - (a < b) as the equivalent for cmp(a, b).)