double underscore attributes?

Steve Holden steve at holdenweb.com
Sun Dec 11 06:08:07 EST 2005


bobueland at yahoo.com wrote:
> Entering
> 
>>>>dir(5)
> 
> 
> I get
> ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
> '__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
> '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__',
> '__hex__', '__init__', '__int__', '__invert__', '__long__',
> '__lshift__', '__mod__', '__mul__', '__neg__', '__new__',
> '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__',
> '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__',
> '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__',
> '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__',
> '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__',
> '__truediv__', '__xor__']
> 
> Every time I use dir(some module) I get a lot of attributes with double
> underscore, for example __add__. Ok, I thought __add__ must be a method
> which I can apply like this
> 
>>>>5.__add(8)
> 
Bzzt.

Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
  >>> 5 . __add__(9)
14
  >>>

[...]
regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list