[英]TypeError: expected str, bytes or os.PathLike object, not list convert
I don't know good at python I want to make a convert of.log files.txt in. html I'm trying to pass the value as an array.我不擅长 python 我想在.log files.txt 中进行转换。 html 我试图将值作为数组传递。 But he doesn't accept it.但他不接受。 How can I fix this TypeError: expected str, bytes or os.PathLike object, not list
?如何修复此TypeError: expected str, bytes or os.PathLike object, not list
? Thank you in advance先感谢您
import txt_to_html
import os
path = 'C:\\Users\\Sandy\\PycharmProjects\\untitled1'
text_files = [f for f in os.listdir(path) if f.endswith('.log')]
txt_to_html.parse_txt(text_files)
You can use below code snippet to achieve what you want.您可以使用下面的代码片段来实现您想要的。
import txt_to_html
import os
path = 'C:\\Users\\Sandy\\PycharmProjects\\untitled1'
text_files = [f for f in os.listdir(path) if f.endswith('.log')]
for file in text_files:
txt_to_html.parse_txt(file)
As far as I understand, txt_to_html.parse_txt
requires the text source, you are passing a list of files that it doesn't understand what to do.据我了解, txt_to_html.parse_txt
需要文本源,您正在传递一个它不知道该怎么做的文件列表。
Modify to -修改为 -
import txt_to_html
import os
path = 'C:\\Users\\Sandy\\PycharmProjects\\untitled1'
text_files = [f for f in os.listdir(path) if f.endswith('.log')]
parsed_op = [txt_to_html.parse_txt(i) for i in text_files]
print(parsed_op[0]) // this will give you the output of first log file.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.