Purpose of operator package

Christian Heimes lists at cheimes.de
Tue May 13 18:38:44 EDT 2008


Eric Anderson schrieb:
> Seems like unnecessary code but obviously I know nothing about Python.

Correct, the truth example isn't a good example. "if argv" is better.
But you can write interesting things with the operator module. For example

>>> import operator
>>> def fac(x):
...     return reduce(operator.mul, range(1, x+1))
...
>>> fac(2)
2
>>> fac(3)
6
>>> fac(4)
24

In general one doesn't use the operator module.

Christian




More information about the Python-list mailing list