>
> Any time you find yourself thinking that you want to use eval to solve a
> problem, take a long, cold shower until the urge goes away.
>
> If you have to ask why eval is dangerous, then you don't know enough
> about programming to use it safely. Scrub it out of your life until you
> have l
mlangenho...@gmail.com writes:
> I would like to pass something like this into a function
> test(val1,val2,'>=')
>
> and it should come back with True or False.
import operator
test(val1, val2, operator.ge)
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 24 May 2012 11:22:37 -0400, Colin J. Williams wrote:
> On 24/05/2012 10:14 AM, mlangenho...@gmail.com wrote:
>> I would like to pass something like this into a function
>> test(val1,val2,'>=')
>>
>> and it should come back with True or False.
>>
>> Is there a way to dynamically compare 2 v
On 24/05/2012 10:14 AM, mlangenho...@gmail.com wrote:
I would like to pass something like this into a function
test(val1,val2,'>=')
and it should come back with True or False.
Is there a way to dynamically compare 2 values like this or will I have to code
each operator individually?
Would so
Alain Ketterlin writes:
> mlangenho...@gmail.com writes:
>
> > I would like to pass something like this into a function
> > test(val1,val2,'>=')
> >
> > and it should come back with True or False.
>
> def test(x,y,c):
> return c(x,y)
>
> Call with: test(v1,v2, lambda x,y:x<=y ). A bit noisy
On 05/24/12 09:32, Phil Le Bienheureux wrote:
>> I would like to pass something like this into a function
>> test(val1,val2,'>=')
>
> You can pass an operator as an argument to your function.
>
> See :
> http://docs.python.org/library/operator.html
And if you want to use strings, you can map them
mlangenho...@gmail.com writes:
> I would like to pass something like this into a function
> test(val1,val2,'>=')
>
> and it should come back with True or False.
def test(x,y,c):
return c(x,y)
Call with: test(v1,v2, lambda x,y:x<=y ). A bit noisy imho.
If you have a finite number of comparis
Hello,
You can pass an operator as an argument to your function.
See :
http://docs.python.org/library/operator.html
Regards,
-- Forwarded message --
From:
Date: 2012/5/24
Subject: Dynamic comparison operators
To: python-list@python.org
I would like to pass something like thi