[Tutor] (no subject)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Feb 3 12:56:23 EST 2004

> Also, this is my first email to a list like this one, so I'm wondering
> if I'm observing proper social conventions. This message feels kind of
> long to me. What do you think?

Hi Dana,

Welcome aboard!  Your message is fine, but make sure to add a "subject
line" on your email, so that it's easier for people to find your message.

(Also, if you haven't already, you may want to subscribe to Tutor ---
otherwise, your messages will be held until one of the lazy admins here
gets a chance to validate the message for non-spaminess.  The page:


explains how to subscribe to Python-Tutor.)

Let's take a look at the InteractiveURLParser:

> class InteractiveURLParser(HTMLParser.HTMLParser):
>     def open(self, URL):
>         page = getPage(URL)
>         page = flattenPage(page)
>         self.feed(page)
>     def newURL(self, URL):
>         __init__(self, URL)
>     def handle_starttag(self, tag, attrs):
>         print "tag is %s with attributes %s." %(self, tag, attrs)
>     def handle_data(self, data):
>         print data

There are two issues I can see so far: the newURL method looks a little
weird, and there's a bug in handle_starttag().  Let's cover the newURL()
method briefly:

>     def newURL(self, URL):
>         __init__(self, URL)

This looks a little weird because no __init__ method has yet been defined.
Can you explain what newURL is trying to do?  And do you need it?  I don't
see anything in the code that uses it, so maybe it can be removed?

Let's take a look at handle_starttag():

>     def handle_starttag(self, tag, attrs):
>         print "tag is %s with attributes %s." %(self, tag, attrs)
                        ^^                 ^^     ^^^^  ^^^  ^^^^^

There are two formatting positions in the string, but the code is trying
to fill it up with three things.  Given that, does the error message:

>   File "r.py", line 31, in handle_starttag
>     print "tag is %s with attributes %s." %(self, tag, attrs)
> TypeError: not all arguments converted during string formatting

make sense now?

Talk to you later!

More information about the Tutor mailing list