469,907 Members | 2,184 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,907 developers. It's quick & easy.

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 1059
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
By using this site, you agree to our Privacy Policy and Terms of Use.