首页 > 解决方案 > TypeError:预期的 str、字节或 os.PathLike 对象,而不是列表转换

问题描述

我不擅长python 我想在.html 中转换.log 文件.txt 我试图将值作为数组传递。但他不接受。我该如何解决这个问题TypeError: expected str, bytes or os.PathLike object, not list?先感谢您

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)

标签: pythonpython-3.x

解决方案


您可以使用下面的代码片段来实现您想要的。

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)

推荐阅读