On Mar 31, 2016, at 14:17 , William Stein wrote:

> On Thu, Mar 31, 2016 at 2:08 PM, Justin C. Walker <jus...@mac.com> wrote:
>> Hi, all,
>> 
>> I have couple of questions regarding "attributes" in Python/Sage:
>> 
>> 1. If hasattr(X, "foo") returns True, does that mean that "X.foo" should not 
>> blow up?
> 
> What's the definition of "blow up"?   I think X.foo could -- due to
> Python "properties" -- run arbitrary Python code, e.g., to launch a
> missile (or raise an exception).

Ooh...I have to try that...

In my particular case, I'm not expecting percussion.  I'm seeing exceptions 
(see following email).

>> 
>> 2. Is there a way to tell, when hasattr(X, "foo") returns True, whether 
>> "X.foo" can be called?
>> 
>> 3. If "X.foo" is callable, is it expected that "X.foo()" will *not* blow up 
>> with "Not Implemented"?
> 
> Not necessarily.
> 
> try:
>    X.foo()
> except (NotImplementedError, AttributeError):
>   ....

That's always the fall-back, I know.  I suppose with object orientation, one 
has to expect this kind of thing...

Thanks!

--
Justin C. Walker, Curmudgeon at Large
Institute for the Absorption of Federal Funds
-----------
I'm beginning to like the cut of his jibberish.
-----------



-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to