Guido van Rossum wrote:
> Examples that keep recurring are things like
> the smtplib.SMTP.sendmail() method, whose second argument is either a
> string or a list of strings. The optimal way of writing this, IMO, is
> a single method that typechecks its 2nd argument. It currently uses
> "if isinstance(x, basestring)" but I'd be happier if this could be
> written as some kind of check for implementing the String interface.
> (If it's neither a string nor a list, I don't really care what
> happens, it will just raise an exception a few lines later and that's
> perfectly fine for diagnosing the problem). Rewriting this as a
> generic method (how do I even create generic methods? I'm sure it's
> easy) sounds like a total waste of time and code.
I'm not sure I see how changing
def sendmail(self, from_addr, to_addr, ...):
if isinstance(to_addr, basestring):
to_addr = [to_addr]
...
to, say
def sendmail(self, from_addr, to_addr is a string, ...): # specific
self.sendmail(from_addr, [to_addr], ...)
def sendmail(self, from_addr, to_addr, ...): # general
...
would be a *total* waste of time. but maybe I've just done too much C#
programming ;-)
</F>
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com