Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread boB Stepp
On Wed, Apr 29, 2015 at 5:49 PM, Peter Otten <__pete...@web.de> wrote: > boB Stepp wrote: >> So I have stumbled (With your gracious help!) into a legitimate use of >> eval()? > > No. To expand on Marks hint here's how to do it without evil eval(). > > import operator > > comps = { > "=": opera

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread boB Stepp
On Wed, Apr 29, 2015 at 4:42 PM, Mark Lawrence wrote: > This isn't a job for Bicycle Repair Man!!! Not even if we only use the latest, greatest, computer-aided bicycle repair technology??? > ... It smacks to me of dictionaries > and the operator module but I'm too bone idle to look it up mysel

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread Danny Yoo
Hi Bob, By the way, it sounds like you're starting to learn about how to write interpreters. If that's the case, you might find PLAI helpful: http://cs.brown.edu/~sk/Publications/Books/ProgLangs/ helpful. (Full disclosure: the author was my external advisor. :P) Another good book is EoP

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread Peter Otten
boB Stepp wrote: > On Wed, Apr 29, 2015 at 3:46 PM, Marc Tompkins > wrote: >> On Wed, Apr 29, 2015 at 1:10 PM, boB Stepp >> wrote: >>> >>> Python 2.4.4, Solaris 10. >>> >>> I have some functions that I believe I could collapse into a single >>> function if I only knew how: >>> >>> def choose_com

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread Laura Creighton
I forget. You are writing these things as functions rather than methods of a class, because you don't know how to use classes yet? Because you are absolutely correct that there are ways to simplify this, but if you don't know how to use classes yet, put this on hold until you do. And this partic

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread Mark Lawrence
On 29/04/2015 21:10, boB Stepp wrote: Python 2.4.4, Solaris 10. I have some functions that I believe I could collapse into a single function if I only knew how: def choose_compare(operator, value0, value1, pass_color, fail_color): """ Perform the comparison indicated by operator. Retu

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread boB Stepp
On Wed, Apr 29, 2015 at 3:50 PM, Laura Creighton wrote: > I forget. You are writing these things as functions rather than > methods of a class, because you don't know how to use classes yet? You forget nothing! ~(:>)) > Because you are absolutely correct that there are ways to simplify this, >

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread boB Stepp
On Wed, Apr 29, 2015 at 3:46 PM, Marc Tompkins wrote: > On Wed, Apr 29, 2015 at 1:10 PM, boB Stepp wrote: >> >> Python 2.4.4, Solaris 10. >> >> I have some functions that I believe I could collapse into a single >> function if I only knew how: >> >> def choose_compare(operator, value0, value1, pa

Re: [Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread Marc Tompkins
On Wed, Apr 29, 2015 at 1:10 PM, boB Stepp wrote: > Python 2.4.4, Solaris 10. > > I have some functions that I believe I could collapse into a single > function if I only knew how: > > def choose_compare(operator, value0, value1, pass_color, fail_color): > """ > Perform the comparison ind

[Tutor] Is there a way to store and later use comparison operators (<, <=, =, >=, >) ?

2015-04-29 Thread boB Stepp
Python 2.4.4, Solaris 10. I have some functions that I believe I could collapse into a single function if I only knew how: def choose_compare(operator, value0, value1, pass_color, fail_color): """ Perform the comparison indicated by operator. Return pass_color if true, fail_color if false