Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61538 > unrolled thread

Re: Differences between obj.attribute and getattr(obj, "attribute")

Started byChris Angelico <rosuav@gmail.com>
First post2013-12-11 20:38 +1100
Last post2013-12-11 20:38 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Differences between obj.attribute and getattr(obj, "attribute") Chris Angelico <rosuav@gmail.com> - 2013-12-11 20:38 +1100

#61538 — Re: Differences between obj.attribute and getattr(obj, "attribute")

FromChris Angelico <rosuav@gmail.com>
Date2013-12-11 20:38 +1100
SubjectRe: Differences between obj.attribute and getattr(obj, "attribute")
Message-ID<mailman.3876.1386754732.18130.python-list@python.org>
On Wed, Dec 11, 2013 at 8:30 PM, Jurko Gospodnetić
<jurko.gospodnetic@pke.hr> wrote:
>   Also, you can not test whether an object has an attribute when using the
> object.attribute access method without raising/catching an exception and
> then it can be hard to make sure no other code caused the exception.

It's pretty easy to make sure no other code caused the exception -
just have no other code inside the try block.

x.foo(input().split(" ")[4])  # Might throw from any point in the expression

try:
   func = x.foo
except AttributeError:
   deal_with_error
func(......)

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web