How to convert a ">" into a >

dominique MyDomDom at gmail.com
Sun Jun 22 10:56:55 EDT 2008


On Jun 22, 6:45 am, Tim Roberts <t... at probo.com> wrote:
> dominique <MyDom... 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, t... at probo.com
> Providenza & Boekelheide, Inc.

Thanks for the tip.
Dominique



More information about the Python-list mailing list