Using an operator as an object

Cameron Laird claird at lairds.com
Mon Mar 3 08:20:42 EST 2003


In article <b3v7ha01gvg at enews3.newsguy.com>,
Alex Martelli  <aleax at aleax.it> wrote:
			.
			.
			.
>Python library.  However, if you DO have a string representing
>an operator, an if/elif tree is still not the best way to find
>out which one of the functions in module operator you have to
>call -- rather, you're probably better off building a dictionary
>once only:
>
>import operator
>string_to_op = {
>    '+': operator.add,
>    '-': operator.sub,
>    '*': operator.mul,
>    '/': operator.div,
>    '%': operator.mod,
>    # and possibly others if you need them, of course
>}
			.
			.
			.
Is such a mapping not already exposed somewhere?
'Near as I can tell, the answer is, "No".  Would
this not be one of the benefits of the (several) 
project(s) to script more of Python's core in
Python?
-- 

Cameron Laird <Cameron at Lairds.com>
Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html




More information about the Python-list mailing list