looking for design pattern name
John J. Lee
jjl at pobox.com
Sun Aug 3 07:13:50 EDT 2003
"Andrew Dalke" <adalke at mindspring.com> writes:
[...]
> Quoting from the docs,
> exception TypeError
> Raised when a built-in operation or function is applied to an object of
> inappropriate type. The associated value is a string giving details about
> the type mismatch.
>
> In addition to your comments, this is not a built-in operation, so it's
> the wrong exception.
[...]
Hmm, I don't think that's what the docs meant to communicate -- you're
allowed to use it in your non-builtin code. At least, that's what
I've always assumed:
def isstringlike(x):
try: x+""
except: return False
else: return True
class Foo:
def __init__(self, stringy):
if not isstringlike(stringy):
raise TypeError("stringy must be string-like")
I don't see anything in that documentation that says that's bad.
John
More information about the Python-list
mailing list