How to convert a ">" into a >
Tim Roberts
timr at probo.com
Sun Jun 22 00:45:49 EDT 2008
dominique <MyDomDom at gmail.com> wrote:
>On Jun 21, 1:37 pm, John Machin <sjmac... at lexicon.net> wrote:
>>
>> Look at the operator module. In your above example:
>>
>> return {
>> '>': operator.gt,
>> '=': operator.eq,
>> '<': operator.lt,
>> }[variable]
>
>Thanks a lot John
>Dominique
Yes, but you need to remember that what you are getting is not literally an
operator. That is, if you store that return value in a variable called
"op", you can't say this:
if x op y:
....
Instead, what you have is a function, so you'll have to write it:
if op( x, y ):
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list