deref in a string into an operand
John Doe
atterdan at yahoo.com
Fri Nov 5 05:13:03 EST 2004
Foolish me; I examined the __builtin__ and found __getattribute__,
along with '__mul__' '__add__', '__sub__' and '__div__'.
So using a builtin object like 'x' ...
x = 5
attr = '__mul__'
print x.__getattribute__( attr )( 5 )
25
My program will store the operand as '__mul__' instead of '*', along with
a health bit of comment.
Dan. Closed.
On Fri, 05 Nov 2004 08:01:59 +0000, John Doe wrote:
> I've got the action '+' stored as the variable 'plus',
> that is plus='+'
>
> Now I want to use the variable plus in an equation:
> 5 plus 7, just line 5 + 7
>
> How do I do that?
>
> Dan
More information about the Python-list
mailing list