【发布时间】:2016-05-03 15:13:04
【问题描述】:
我正在尝试使用 glob.glob 在我的个人计算机中读取多个文件,如下所示:
diri = r"C:\Users\Hoonill\Desktop\Python\BAO\2007\2011"
filin = diri + '\*10*datresult'
FileList=sorted(glob.glob(filin))
print(FileList)
我的预期结果是这样的系列
'C:\Users\Hoonill\Desktop\Python\BAO\2007\2011\BAO_100_2011229.datresult',
但我得到的是系列
'C:\\Users\\Hoonill\\Desktop\\Python\\BAO\\2007\\2011\\BAO_100_2011229.datresult'
我不知道为什么'\' 变成了'\\'。
根据其他人的建议,这个结果似乎是由于在文件路径上添加了 'r',但没有 'r',我得到“SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2 -3:截断 \UXXXXXXXXXX 转义。”
任何想法或帮助将不胜感激。
最好的问候,
艾萨克
【问题讨论】:
-
另一个已经回答的例子:stackoverflow.com/questions/11924706/…
-
谢谢 Rob,问题是我应该使用 'r',因为 eol 字符串错误。