简体   繁体   English

类型错误:预期的 str、字节或 os.PathLike object,不是列表转换

[英]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.

相关问题 类型错误:预期的 str、bytes 或 os.PathLike 对象,而不是 DataFrame - Not a Repost - TypeError: expected str, bytes or os.PathLike object, not DataFrame - Not a Repost 类型错误:预期的 str、bytes 或 os.PathLike 对象,而不是 None 类型 - TypeError: expected str, bytes or os.PathLike object, not None Type TypeError:预期的 str、字节或 os.PathLike 对象,而不是 Image - TypeError: expected str, bytes or os.PathLike object, not Image Django TypeError:预期的 str、bytes 或 os.PathLike object,不是 NoneType - Django TypeError: Expected str, bytes or os.PathLike object, not NoneType 类型错误:应为 str、字节或 os.PathLike object,而不是文件 - TypeError: expected str, bytes or os.PathLike object, not File 类型错误:预期的 str、bytes 或 os.PathLike 对象,而不是 GeojsonFile - TypeError: expected str, bytes or os.PathLike object, not GeojsonFile pyqtdeploy : TypeError: 预期的 str、bytes 或 os.PathLike 对象,而不是 NoneType - pyqtdeploy : TypeError: expected str, bytes or os.PathLike object, not NoneType 类型错误:预期的 str、bytes 或 os.PathLike 对象,而不是 int in - 子进程 - TypeError: expected str, bytes or os.PathLike object, not int in - subprocess 类型错误:预期的 str、字节或 os.PathLike object,不是 dict - TypeError: expected str, bytes or os.PathLike object, not dict 类型错误:预期的 str、bytes 或 os.PathLike 对象,而不是 FieldFile - TypeError: expected str, bytes or os.PathLike object, not FieldFile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM