What about adding the following function to basic.py:
def count_chars(self):
"""
Return the number of characters in expressions.
"""
return len(str(self))
Perhaps call it len?
--
You received this message because you are s
hmm
'Mul' object has no attribute 'count_chars'
On Nov 30, 12:38 pm, freevryheid wrote:
> What about adding the following function to basic.py:
>
> def count_chars(self):
> """
> Return the number of characters in expressi
t_chars(self):
> > """
> > Return the number of characters in expressions.
> >
> > """
> > return len(str(self))
> >
> > Perhaps call it len?
>
What would be the point? len(str(expr)) is perfe
ribute 'count_chars'
>
> > On Nov 30, 12:38 pm, freevryheid wrote:
> > > What about adding the following function to basic.py:
>
> > > def count_chars(self):
> > > """
> > > Return the number of characters
>> Le mardi 30 novembre 2010 à 10:42 -0800, freevryheid a écrit :
>>
>>> hmm
>>
>>> 'Mul' object has no attribute 'count_chars'
>>
>>> On Nov 30, 12:38 pm, freevryheid wrote:
>>>> What about adding the following fu
Le mardi 30 novembre 2010 à 14:58 -0700, Aaron S. Meurer a écrit :
> There is also .count_ops(), which is faster and also gives a better
> insight into the actual size of an expression, since it doesn't give
> more weight to " + " and to symbols and numbers that are more than one
> character long.
2010/11/30 Aaron S. Meurer
> By the way, is there an easy way to get the string version of the pretty
> printed form of an expression? I couldn't find anything.
It's called pretty() (analogically to latex() etc.). (srepr() is to get the
eval()'able representation btw.)
Vinzent
--
You receiv
> .count_ops() is rather quirky and not really generic.
> To get the number of nodes in the expression tree, you can do:
When 1923 gets pushed you will find it to be less quirky, I believe.
Also, when 2003 gets pushed, Aaron, there is a capture function that
will capture any output into a string.