且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

读取日志文件并在其中打开文件

更新时间:2023-09-29 23:33:16

您只需要删除换行符,然后进行更改

You just need to strip the newline character so change

read_files = open(lines)

read_files = open(lines.strip())

作为观察结果-读取错误消息中的每个字符至关重要-该消息告诉您没有名为

as an observation - critical to read each character in an error message - the message was telling you that there was no file named

'/home/usr/Downloads/outdir/unpacked_files.log\n'

因此很有用然后尝试理解为什么显示\ n的原因-这与您对文件名的期望不符,因此您应该怀疑为什么文件具有该名称

so it is useful to then try to understand why the \n showed up - this did not match your expectation of the file name so you should wonder why the file has that name