Cannot import htmllib

geir.smestad at gmail.com geir.smestad at gmail.com
Thu Apr 13 08:04:51 EDT 2006


Using Ubuntu Breezy Badger 5.10. I get the following traceback:

-----
Traceback (most recent call last):
  File "/home/geir/programmering/htmlparse/formatter.py", line 1, in
-toplevel-
    import formatter
  File "/home/geir/programmering/htmlparse/formatter.py", line 2, in
-toplevel-
    import htmllib
  File "/usr/lib/python2.4/htmllib.py", line 9, in -toplevel-
    from formatter import AS_IS
ImportError: cannot import name AS_IS
-----

I have been unable to make the following code execute on my Ubuntu
system, and the error above started occurring after I attempted to
execute it. Libraries were imported successfully:

-----
#!/usr/bin/python

import formatter
import htmllib
import urllib
import iface

def fetch(url):
    """Fetches URL to string"""
    object = urllib.urlopen(url)
    string = object.read()
    return string

def plaintext(data, outfile):
    """Formats HTML to plain-text outfile"""
    w = formatter.DumbWriter(outfile)
    f = formatter.AbstractFormatter(w)
    p = htmllib.HTMLParser(f)
    p.feed(data)
    p.close()
-----

I do not have a copy of the traceback, but the final message was
something along the lines of 'str' object does not have attribute
'write'.

As far as I can see, the files formatter.py and htmllib.py are where
they are supposed to be, in /usr/lib/python2.4/.

Geir Smestad




More information about the Python-list mailing list