Cannot import htmllib

G

geir.smestad

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
 
R

Richard Brodie

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.
 
F

Fredrik Lundh

-----
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>
 
G

geir.smestad

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top