pythonhtmldominate

How to generate my Python output as a HTML?


I tried this to generate my Python output in a HTML:

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

The HTML part is working fine if I hardcoded the path in the os.listdir. But it shows an 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.


Solution

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