<br><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">So here's a two-part proposal that would solve Zaheri's problem:
<br>
<br>1) Enhance AttributeError to include arguments for the parts in
<br>quotes, for i18n independence.
<br>2) Provide, in the docs, a hasattr replacement that checks the exception's args.
<br>
<br>The new hasattr would look like this:
<br>
<br>def hasattr(obj, name):
<br>    try:
<br>        getattr(obj, name)
<br>        return True
<br>    except AttributeError as e:
<br>        if e.args[1] == obj.__class__.__name__ and e.args[2] == name:
<br>            return False
<br>        raise
<br>
<br>Since it's just a recipe in the docs, you could also have a version
<br>that works on current Pythons, but it'd need to do string manipulation
<br>to compare - something like:
<br>
<br>def hasattr(obj, name):
<br>    try:
<br>        getattr(obj, name)
<br>        return True
<br>    except AttributeError as e:
<br>        if e.args[0] == "%r object has no attribute %r" % (
<br>                obj.__class__.__name__, name):
<br>            return False
<br>        raise
<br>
<br>I can't guarantee that this doesn't get some edge cases wrong, eg if
<br>you have weird characters in your name. But it'll deal with the normal
<br>cases, and it doesn't need any language changes - just paste that at
<br>the top of your file.
<br>
<br>Zaheri, would this solve your problem?
<br></blockquote><div><br>This looks like a good idea. Note that there is also getattr(X(), 'y', 'default') that would have to behave like this.<br><br>Cheers,<br><br>Zahari<br><br> </div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>ChrisA
<br>______________________________<wbr>_________________
<br>Python-ideas mailing list
<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="3QLTrIItDwAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">Python...@python.org</a>
<br><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;" onclick="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a>
<br>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;">http://python.org/psf/<wbr>codeofconduct/</a>
<br></blockquote>