How to generate my python output as a HTML

375 views Asked by At
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())

I tried this, to generate my python output in a HTML.
The HTML part is working fine if I hardcode the path in the os.listdir
But it shows error if I use path as input.

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

This is the Error
TypeError: listdir: path should be string, bytes, os.PathLike or None, not input_

I even tried a library yattag
I have a List[] in python, which I have to loop and print as a list in HTML.
I tried in yattag and I can't achieve, I'm not sure what I did wrong.
Is there any other libraries I should use to achieve my output.
Please give me some suggestions.

1

There are 1 answers

0
JoJo On BEST ANSWER

The error is because of the wildcard imports.from dominate.tags import *. dominate.tags defines an input class that shadowed the builtin input() function.

This code works fine without the error.

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())