By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,421 Members | 1,233 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,421 IT Pros & Developers. It's quick & easy.

How to convert a ">" into a >

P: n/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
Share this Question
Share on Google+
4 Replies

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.