1
import dominate
from dominate.tags import *
doc = dominate.document(title='Cell Value report')
with doc:
    with div():
        attr(cls='body')
        h2('Values Missing in the files.....')
    with div(id='header').add(ol()):
        for i in unique_file:
            li(i.title())

我试过这个,以 HTML 格式生成我的 python 输出。
如果我硬编码路径中的路径,HTML 部分工作正常,os.listdir
但如果我使用路径作为输入,它会显示错误。

search_path = input("Enter directory path to search: ")#directory path
for fname in os.listdir(path=search_path):

这是错误
TypeError: listdir: path should be string, bytes, os.PathLike or None, not input_

我什至尝试了一个我在 python 中拥有的库 yattag 我必须将其循环并打印为 HTML 中的列表。我在yattag中尝试过,但我无法实现,我不确定我做错了什么。是否有任何其他库我应该使用来实现我的输出。请给我一些建议。
List[]


4

1 回答 1

2

该错误是由于通配符导入造成的。from dominate.tags import *. dominate.tags定义一个input隐藏内置input()函数的类。

此代码工作正常,没有错误。

from dominate import tags
with doc:
    with tags.div():
        tags.attr(cls='body')
        tags.h2('Values Missing in the files.....')
    with tags.div(id='header').add(tags.ol()):
        for i in unique_file:
            tags.li(i.title())
于 2020-03-31T10:44:56.600 回答