On May 13, 7:46 pm, Carl Banks <[EMAIL PROTECTED]> wrote:
> On May 13, 6:09 pm, Eric Anderson <[EMAIL PROTECTED]> wrote:
>
> > 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).
>
> There is one significant drawback of that....
>
> > 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.
>
> It isn't.  The above is terrible code.
>
> 1. You don't even need operator.truth; the built-in bool performs that
> job.  However, this code could have been written before the advent of
> bool, so we'll give it a temporary pass.
> 2. bool in unnecessary in this context.
> 3. Lest someone claim that truth serves to document that you are
> asking for the boolean value of argv (i.e., whether it's not empty),
> it's redundnant since the if statement implies that.

4. sys.argv is never false.  I presume that that the first item of
argv was removed, or argv is a copy of sys.argv without the first
element.  Either way is bad style IMO.  Leave sys.argv alone, and if
you copy it without the first element, copy it to a differently-named
variable.



Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to