Operator Overloading

Calvin Spealman ironfroggy at gmail.com
Mon Aug 1 11:12:46 EDT 2005


On 1 Aug 2005 05:12:47 -0000, Gurpreet Sachdeva
<redhackgp at rediffmail.com> wrote:
>  Hi,
>  
>  Is there any provision in python which allows me to make my own operators?
>  
>  My problem is that I need to combine two dictonaries with their keys and I
> don't want to use any of the existing operators like '+','-','*'.
>  So is there a way I can make '**' or '~' as my operators to add two
> dictonaries? If not which all operators can I overoad?
>  
>  Thanks,
>  Garry

Why do you need to add operators for this? Why not use the
dictionary's update method? it also has the benefit of being much
clearer.

# Get our two dictionaries
d1 = foo()
d2 = bar()
# And merge them into a third
d3 = {}
d3.update(d1)
d3.update(d2)



More information about the Python-list mailing list