Because, if you assume that each class has is_Class set to True for itself, you 
can just use getattr(object, 'is_Class', False) (sorry, I meant getattr(), not 
hasattr()).  For __getattr__, you could set that in Basic and make it recognize 
is_Class.  I don't know if that will still have the speed of the direct 
is_Class that we are having now, but it least it could handle classes that 
Basic doesn't know about.

Aaron Meurer

On Sep 23, 2010, at 8:21 PM, Andy Ray Terrel wrote:

> How would hasattr help you?  It doesn't tell you if there is a
> instance of a class in the arg tree only if the instance has a
> specific attribute.  I guess nobody has needed __getatrr__ yet.
> 
> -- Andy
> 
> On Thu, Sep 23, 2010 at 8:50 PM, Aaron S. Meurer <asmeu...@gmail.com> wrote:
>> How does the speed compare if you use hasattr()?  Also, is there a good 
>> reason that Basic doesn't have __getattr__() implemented?
>> 
>> Aaron Meurer
>> 
>> On Sep 23, 2010, at 7:42 PM, Andy Ray Terrel wrote:
>> 
>>> The problem with the is_Foo construct is that every basic has to carry
>>> it, so every object grows.  The reason (maybe historic) there are some
>>> there is that its faster to ask is_Foo than to do isinstance a lot and
>>> the core needs some faster things. For bits that aren't checked very
>>> much we should try to keep it out of the core (maybe put it in the
>>> assumptions).
>>> 
>>> Of course once Indexed elements start propogating to other modules it
>>> might be necessary to do this. For now I vote that we either include a
>>> depth first search for the properties.
>>> 
>>> -- Andy
>>> 
>>> On Thu, Sep 23, 2010 at 6:27 PM, Nicholas Kinar <n.ki...@usask.ca> wrote:
>>>> 
>>>>> You should also know about pre/post_order_traversal (both must be imported
>>>>> from sympy.utilities.iterables), which let you dig all the way down in an
>>>>> expression tree.
>>>>> 
>>>>> In [109]: from sympy.utilities.iterables import preorder_traversal,
>>>>> postorder_traversal
>>>>> 
>>>>> In [110]: preorder_traversal(sin(x**2) + 4*x**3)
>>>>> Out[110]:<generator object preorder_traversal at 0x102415a00>
>>>>> 
>>>>> In [111]: list(preorder_traversal(sin(x**2) + 4*x**3))
>>>>> Out[111]:
>>>>> ⎡   ⎛ 2⎞      3     3      3           ⎛ 2⎞   2      ⎤
>>>>> ⎣sin⎝x ⎠ + 4⋅x , 4⋅x , 4, x , x, 3, sin⎝x ⎠, x , x, 2⎦
>>>>> 
>>>>> In [112]: list(postorder_traversal(sin(x**2) + 4*x**3))
>>>>> Out[112]:
>>>>> ⎡          3     3         2     ⎛ 2⎞     ⎛ 2⎞      3⎤
>>>>> ⎣4, x, 3, x , 4⋅x , x, 2, x , sin⎝x ⎠, sin⎝x ⎠ + 4⋅x ⎦
>>>>> 
>>>>> Also, as Chris said, using .atoms() to find what IndexedElements there are
>>>>> is useful.  There maybe ought to be some .is_IndexedElement attribute on
>>>>> IndexedElement, just as there is for every other major class.  Øyvind, 
>>>>> what
>>>>> do you think?
>>>>> 
>>>>> Aaron Meurer
>>>>> 
>>>>> 
>>>> 
>>>> Thanks, Aaron; I also agree that there should be some way to check and see
>>>> if a class is of a particular type, and it would be terrific if
>>>> IndexedElement would also have this.
>>>> 
>>>> Nicholas
>>>> 
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "sympy" group.
>>>> To post to this group, send email to sy...@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> sympy+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/sympy?hl=en.
>>>> 
>>>> 
>>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "sympy" group.
>>> To post to this group, send email to sy...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> sympy+unsubscr...@googlegroups.com.
>>> For more options, visit this group at 
>>> http://groups.google.com/group/sympy?hl=en.
>>> 
>> 
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "sympy" group.
>> To post to this group, send email to sy...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> sympy+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/sympy?hl=en.
>> 
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to