472,126 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

How to convert a ">" into a >

Hello All,

In a wx GUI, I would like to let the user choose between >, < or =.
So, I created a combobox and when the user chooses ">" for instance, I
wanted to return (the objective is to send the operator into another
complex method):
Example:
if variable == ">":
return >

But this is invalid syntax.

How can I transform a ">" into the operator ie without parenthesis,
so that I can load it into another function ?

Thanks in advance

Dominique
Jun 27 '08 #1
4 1128
On Jun 21, 9:17 pm, dominique <MyDom...@gmail.comwrote:
Hello All,

In a wx GUI, I would like to let the user choose between >, < or =.
So, I created a combobox and when the user chooses ">" for instance, I
wanted to return (the objective is to send the operator into another
complex method):
Example:
if variable == ">":
return >

But this is invalid syntax.

How can I transform a ">" into the operator ie without parenthesis,
so that I can load it into another function ?
Look at the operator module. In your above example:

return {
'>': operator.gt,
'=': operator.eq,
'<': operator.lt,
}[variable]

Cheers,
John
Jun 27 '08 #2
On Jun 21, 1:37 pm, John Machin <sjmac...@lexicon.netwrote:
>
Look at the operator module. In your above example:

return {
'>': operator.gt,
'=': operator.eq,
'<': operator.lt,
}[variable]

Cheers,
John
Thanks a lot John
Dominique
Jun 27 '08 #3
dominique <My******@gmail.comwrote:
>On Jun 21, 1:37 pm, John Machin <sjmac...@lexicon.netwrote:
>>
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, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 27 '08 #4
On Jun 22, 6:45 am, Tim Roberts <t...@probo.comwrote:
dominique <MyDom...@gmail.comwrote:
On Jun 21, 1:37 pm, John Machin <sjmac...@lexicon.netwrote:
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...@probo.com
Providenza & Boekelheide, Inc.
Thanks for the tip.
Dominique
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Eric A. Forgy | last post: by
1 post views Thread by Christian Schmidbauer | last post: by
7 posts views Thread by Diandian Zhang | last post: by
6 posts views Thread by Eidolon | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.