输入文件不存在,即使在正确的位置pysp中提到了该文件

2024-09-25 16:24:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过形成键值对来读取日志行,但是我得到了一个错误。 这是我的代码:

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的新手。在


Tags: 代码inlogfor错误linerxtesting
2条回答

当在字符串中找到字符序列\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()

反斜杠字符不是字符串中的'\',而是"\\"

相关问题 更多 >