Re: Using String Methods In Jump Tables

2010-08-25 Thread Bruno Desthuilliers
Tim Daneliuk a écrit : On 8/19/2010 7:23 PM, Steven D'Aprano wrote: On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: Problem: Given tuples in the form (key, string), use 'key' to determine what string method to apply to the string: table = {'l': str.lower, 'u': str.upper}

Re: Using String Methods In Jump Tables

2010-08-24 Thread Tim Daneliuk
On 8/23/2010 4:22 PM, Hrvoje Niksic wrote: Tim Daneliuk tun...@tundraware.com writes: You can get away with this because all string objects appear to point to common method objects. That is,: id(a.lower) == id(b.lower) A side note: your use of `id' has misled you. id(X)==id(Y) is

Re: Using String Methods In Jump Tables

2010-08-24 Thread John Pinner
On Aug 20, 12:27 am, Tim Daneliuk tun...@tundraware.com wrote: Problem:   Given tuples in the form (key, string), use 'key' to determine   what string method to apply to the string:     key           operation     ---      l            lower()      u            

Re: Using String Methods In Jump Tables

2010-08-23 Thread Jon Clements
On 20 Aug, 01:51, Tim Daneliuk tun...@tundraware.com wrote: On 8/19/2010 7:23 PM, Steven D'Aprano wrote: On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: Problem:   Given tuples in the form (key, string), use 'key' to determine what   string method to apply to the string:

Re: Using String Methods In Jump Tables

2010-08-23 Thread Tim Daneliuk
On 8/23/2010 10:35 AM, Jon Clements wrote: On 20 Aug, 01:51, Tim Daneliuk tun...@tundraware.com wrote: On 8/19/2010 7:23 PM, Steven D'Aprano wrote: On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: Problem: Given tuples in the form (key, string), use 'key' to determine what

Re: Using String Methods In Jump Tables

2010-08-23 Thread Terry Reedy
On 8/23/2010 11:57 AM, Tim Daneliuk wrote: On 8/23/2010 10:35 AM, Jon Clements wrote: Another more generic option would be to use methodcaller from the operator module. Could you say a bit more about just why you prefer this approach? Clearly, it *is* more generic, but in looking it over,

Re: Using String Methods In Jump Tables

2010-08-23 Thread Jon Clements
On 23 Aug, 16:57, Tim Daneliuk tun...@tundraware.com wrote: On 8/23/2010 10:35 AM, Jon Clements wrote: On 20 Aug, 01:51, Tim Daneliuk tun...@tundraware.com wrote: On 8/19/2010 7:23 PM, Steven D'Aprano wrote: On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: Problem:   Given

Re: Using String Methods In Jump Tables

2010-08-23 Thread Hrvoje Niksic
Tim Daneliuk tun...@tundraware.com writes: You can get away with this because all string objects appear to point to common method objects. That is,: id(a.lower) == id(b.lower) A side note: your use of `id' has misled you. id(X)==id(Y) is not a perfect substitue for the X is Y. :)

Using String Methods In Jump Tables

2010-08-19 Thread Tim Daneliuk
Problem: Given tuples in the form (key, string), use 'key' to determine what string method to apply to the string: key operation --- llower() uupper() ttitle() ... Commentary: Easy, right?

Re: Using String Methods In Jump Tables

2010-08-19 Thread Chris Rebert
On Thu, Aug 19, 2010 at 4:27 PM, Tim Daneliuk tun...@tundraware.com wrote: Problem:  Given tuples in the form (key, string), use 'key' to determine  what string method to apply to the string:    key           operation    ---     l            lower()     u            

Re: Using String Methods In Jump Tables

2010-08-19 Thread Steven D'Aprano
On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: Problem: Given tuples in the form (key, string), use 'key' to determine what string method to apply to the string: table = {'l': str.lower, 'u': str.upper} table['u']('hello world') 'HELLO WORLD' [...] As I said, I know I

Re: Using String Methods In Jump Tables

2010-08-19 Thread Tim Daneliuk
On 8/19/2010 7:23 PM, Steven D'Aprano wrote: On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: Problem: Given tuples in the form (key, string), use 'key' to determine what string method to apply to the string: table = {'l': str.lower, 'u': str.upper} table['u']('hello world')

Re: Using String Methods In Jump Tables

2010-08-19 Thread Tim Daneliuk
On 8/19/2010 6:41 PM, Chris Rebert wrote: SNIP snip How do you get a reference to a method found in one object instance, but actually apply it to another instance of the same class? I'm guessing this may involve fiddling with some of the internal __ variables, but I'm not quite