Purpose of operator package

Eric Anderson eric at pixelwareinc.com
Tue May 13 18:09:17 EDT 2008


I mainly work in other languages (mostly Ruby lately) but my text
editor (Scribes) is python. With python being everywhere for dynamic
scripting I thought I would read the source to learn the language
better (I've gone through some basic tutorials but I always prefer to
learn from real source).

So right from the start I see the following:

from operator import truth
if truth(argv):
  # blah blah blah

It is obvious they are testing to see if any command line arguments.
But curious for why the function is needed. So I look up the operator
package and fine it provides functions that are equivalent to the
native operators. So my question is why would someone right the above
instead of just

if argv:
  # blah blah blah

Seems like unnecessary code but obviously I know nothing about Python.

Thanks for any pointers!



More information about the Python-list mailing list