[BioPython] Perl Question

Andrew Dalke dalke@dalkescientific.com
Mon, 6 Jan 2003 13:23:41 -0700


tarjei@genome.wi.mit.edu:
> Although if you follow the advice of that code
> 
> (a1, c, a2) = (0, "<", 1)
> if eval("%s %s %s" % (a1, c, a2)): print "Much better"
> 
> isn't so bad either. And if you're feeling adventerous, you could try
> 
> f = lambda x,y: x < y                   
> if f(0,1): print "Pssseudo functional programming"

The eval code can be nasty if somehow one of the input terms is a
string like

__import__("shutil").rmtree(__import("os").environ["HOME"])

Eval is usually a bad way to solve a problem.

Also, take a look at the operator module.  In the above you could
have done

f = operator.lt

					Andrew
					dalke@dalkescientific.com