470,855 Members | 1,166 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Cannot import htmllib

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

Apr 13 '06 #1
3 2112

<ge**********@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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/.


You probably have aliased it by calling your main program formatter.py,
or something similar.
Apr 13 '06 #2
ge**********@gmail.com wrote:
-----
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
----- 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/.


not only that, but according to the traceback, you also have a formatter
module under

/home/geir/programmering/htmlparse

(by default, the current directory is part of the system path).

</F>

Apr 13 '06 #3
Thanks a lot! You are quite right.

(By the way, this is the first time ever I post something to a
newsgroup. Thanks for giving me a good first impression :D)

Apr 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by KC | last post: by
reply views Thread by Achim Domma | last post: by
reply views Thread by Morten W. Petersen | last post: by
1 post views Thread by huwjeffries | last post: by
1 post views Thread by David Bear | last post: by
1 post views Thread by vsp15584 | last post: by
1 post views Thread by Shiva48 | last post: by
2 posts views Thread by karinmorena | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.