背景:
有个conf配置如下
[ENV]
[DIFF_DIR]
[DIF_DETAIL]
FILE_1=name,sex,hight,weight,ignore
FILE_2=name,age,hight,weight,ignore
MAP_LIST=
ARRARY_LIST=
USER_DEFINED_LIST=
KEY_LIST=name
INGNOR_LIST=ignore
SEPARATOR_USER_FILE1=\t
FILE_LABLE1=qaoutput
FILE_LABLE2=rdoutput
可以看到SEPARATOR_USER_FILE1=\t想表示的为文本分割符为\t(TAB),当通过ConfigParser读取时,input_string = cf.get('DIF_DETAIL', SEPARATOR_USER_FILE1),input_string 实际为\\t,因此会对后面的操作带来不便。
可以使用str.decode("string-escape")方式将结果转义后的字符串转化为你想要的字符串。