我试图通过形成键值对来读取日志行,但是我得到了一个错误。 这是我的代码:
logLine=sc.textFile("C:\TestLogs\testing.log").cache()
lines = logLine.flatMap(lambda x: x.split('\n'))
rx = "(\\S+)=(\\S+)"
line_collect = lines.collect()
for line in line_collect :
d = dict([(x,y) for x,y in re.findall(rx,line)])
d = str(d)
print d
错误:
line_collect = lines.collect()......InvalidInputException: Input path does not exist: file:/C:/TestLogs esting.log
我不知道怎么改正。我是python和spark的新手。在
当在字符串中找到字符序列
\t
时,它将被替换为制表符。您可以在错误消息中看到这一点。在我建议始终使用正斜杠
/
作为目录分隔符,即使在Windows上也是如此。或者在字符串前面加上这样的r:r"does not replace \t with <tab>."
。在您可能需要阅读字符串文字:https://docs.python.org/2.0/ref/strings.html。在
尝试将
logLine=sc.textFile("C:\TestLogs\testing.log").cache()
替换为logLine=sc.textFile("C:\\TestLogs\\testing.log").cache()
反斜杠字符不是字符串中的
'\'
,而是"\\"
相关问题 更多 >
编程相关推荐