Cannot import htmllib

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • geir.smestad@gmail.com

    #1

    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.DumbW riter(outfile)
    f = formatter.Abstr actFormatter(w)
    p = htmllib.HTMLPar ser(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

  • Richard Brodie

    #2
    Re: Cannot import htmllib


    <geir.smestad@g mail.com> wrote in message
    news:1144929891 .548732.140220@ i40g2000cwc.goo glegroups.com.. .
    [color=blue]
    > 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/.[/color]

    You probably have aliased it by calling your main program formatter.py,
    or something similar.


    Comment

    • Fredrik Lundh

      #3
      Re: Cannot import htmllib

      geir.smestad@gm ail.com wrote:
      [color=blue]
      > -----
      > 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
      > -----[/color]
      [color=blue]
      > 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/.[/color]

      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>



      Comment

      • geir.smestad@gmail.com

        #4
        Re: Cannot import htmllib

        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)

        Comment

        Working...