dictionary of operators

A.T.Hofkamp hat at se-162.se.wtb.tue.nl
Fri Feb 15 02:56:43 EST 2008


On 2008-02-14, rbossy at jouy.inra.fr <rbossy at jouy.inra.fr> wrote:
> Hi,
>
> In the standard library module "operator", it would be nice to have a dictionary
> mapping operators strings with their respective functions. Something like:
>
>   {
>     '+': add,
>     '-': sub,
>     'in': contains,
>     'and': and_,
>     'or': or_,
>     ...
>   }
>
> Does such a dictionary already exist? Is it really a good and useful idea?

How would you handle changes in operator syntax?
- I have 'add' instead of '+'
- I have U+2208 instead of 'in'

I don't think this is generally applicable.


Why don't you attach the function to the +/-/in/... token instead? Then you
don't need the above table at all.


sincerely,
Albert



More information about the Python-list mailing list