#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    10
    Rep Power
    0

    need a bit of help with htmllib


    import htmllib
    import formatter

    w = formatter.DumbWriter()
    f = formatter.AbstractFormatter(w)

    file = open("assign.html")

    parser = htmllib.HTMLParser(f)
    parser.feed(open('assign.html').read())
    parser.close()

    ###################

    I've recently began to learn python, so i need a bit of help. Instead of outputting the text on the screen how can i store it in a string or a text file?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    Pass an instance of a file (or file-like) object to the constructor for DumbWriter().

    to write to a string you can use a StringIO object, which behaves like a file, but stores the 'file' in memory so that you can extract it later as a string.

    Dave - The Developers' Coach

IMN logo majestic logo threadwatch logo seochat tools logo