Number of characters in expressions

2010-11-30 Thread freevryheid
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

Re: Number of characters in expressions

2010-11-30 Thread freevryheid
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

Re: Number of characters in expressions

2010-11-30 Thread Ronan Lamy
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

Re: Number of characters in expressions

2010-11-30 Thread freevryheid
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

Re: Number of characters in expressions

2010-11-30 Thread Aaron S. Meurer
>> 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

Re: Number of characters in expressions

2010-11-30 Thread Ronan Lamy
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.

Re: Number of characters in expressions

2010-11-30 Thread Vinzent Steinberg
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

Re: Number of characters in expressions

2010-11-30 Thread smichr
> .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.