Search code examples
pythonwxpython

Python Class is Undefined?


I have written the following class in my .py script. Why does it keep coming back as HTMLEasyPrinting is undefined. That's a function/class in wxPython which I imported with "import wx"

Code:

#Printer Class
class Printer(HtmlEasyPrinting):
    def __init__(self):
        HtmlEasyPrinting.__init__(self)

    def GetHtmlText(self,text):
        html_text = '<h3>Data Results:</h3><p><table border="2">'
        html_text += "<tr><td>Domain:</td><td>Mail Server:</td><td>TLS:</td><td># of Employees:</td><td>Verified</td></tr>"
        for row in root.pt.get_rows():
            html_text += "<tr>"
            for x in range(len(row)):
                html_text += "<td>"+str(row[x])+"</td>"
            html_text += "</tr>"
        return html_text + "</table></p>"

    def Print(self, text, doc_name):
        self.SetHeader(doc_name)
        self.PrintText(self.GetHtmlText(text),doc_name)

    def PreviewText(self, text, doc_name):
        self.SetHeader(doc_name)
        HtmlEasyPrinting.PreviewText(self, self.GetHtmlText(text))

Solution

  • You have a two choices.

    One, you can use the full name.

    class Printer(wx.HtmlEasyPrinting):
    

    Two, you can import the object from wx

    from wx import HtmlEasyPrinting
    

    Based on the documentation, HtmlEasyPrinting lives inside wx.html, so you need to change wx to wx.html everywhere.

    Option 1

    import wx.html
    class Printer(wx.html.HtmlEasyPrinting):
    

    Option 2

    from wx.html import HtmlEasyPrinting