Re: how to dynamically create class methods ?

2008-03-27 Thread Steven D'Aprano
On Wed, 26 Mar 2008 00:27:17 -0700, Arnaud Delobelle wrote: I'm hardly surprised. The naivety of those who insist that the best way to understand how new.function and new.code work is to look at the C source code for object is amusing. Since 'those who insist...' are just one person, me,

Re: how to dynamically create class methods ?

2008-03-27 Thread Steven D'Aprano
On Wed, 26 Mar 2008 00:55:22 -0700, Arnaud Delobelle wrote: [snip] Except it only *appears* to work. What happens if were store the instances in a list and then execute them all in one go? Ah yes, nicely spotted. Another solution would be to use a proper factory function: def

Re: how to dynamically create class methods ?

2008-03-26 Thread Arnaud Delobelle
On Mar 25, 10:55 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Tue, 25 Mar 2008 14:17:16 -0600, j vickroy wrote: As per your suggestion, I tried looking at include/code.h and include/funcobject.h (my MS Windows distribution does not appear to contain .c files).  

Re: how to dynamically create class methods ?

2008-03-26 Thread Arnaud Delobelle
On Mar 25, 10:55 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: [...] In my haste I forgot to finish my post: Here's an example that might help. class MyClass(object):     pass records = [spam, ham] for record in records:     # define a new function     def f(n):      

how to dynamically create class methods ?

2008-03-25 Thread j vickroy
Hello, Here is some pseudo-code that hopefully illustrates what I want to do: records = list(...) for record in records: new_fcn = define_a function_for(record) instance = my_new_class_instance() setattr(instance, 'myfcn', new_fcn) instance.execute() # instance.execute() calls

Re: how to dynamically create class methods ?

2008-03-25 Thread Arnaud Delobelle
On Mar 25, 6:13 pm, j vickroy [EMAIL PROTECTED] wrote: Hello, Here is some pseudo-code that hopefully illustrates what I want to do: records = list(...) for record in records:     new_fcn = define_a function_for(record)     instance = my_new_class_instance()     setattr(instance, 'myfcn',

Re: how to dynamically create class methods ?

2008-03-25 Thread j vickroy
Arnaud Delobelle wrote: On Mar 25, 6:13 pm, j vickroy [EMAIL PROTECTED] wrote: Hello, Here is some pseudo-code that hopefully illustrates what I want to do: records = list(...) for record in records: new_fcn = define_a function_for(record) instance = my_new_class_instance()

Re: how to dynamically create class methods ?

2008-03-25 Thread Gabriel Genellina
En Tue, 25 Mar 2008 17:17:16 -0300, j vickroy [EMAIL PROTECTED] escribió: Arnaud Delobelle wrote: On Mar 25, 6:13 pm, j vickroy [EMAIL PROTECTED] wrote: Hello, Here is some pseudo-code that hopefully illustrates what I want to do: records = list(...) for record in records: new_fcn

Re: how to dynamically create class methods ?

2008-03-25 Thread Steven D'Aprano
On Tue, 25 Mar 2008 14:17:16 -0600, j vickroy wrote: As per your suggestion, I tried looking at include/code.h and include/funcobject.h (my MS Windows distribution does not appear to contain .c files). However, since I'm not a C programmer, I did not find the .h files all that helpful. I'm

Re: how to dynamically create class methods ?

2008-03-25 Thread jv
Steven D'Aprano wrote: On Tue, 25 Mar 2008 14:17:16 -0600, j vickroy wrote: As per your suggestion, I tried looking at include/code.h and include/funcobject.h (my MS Windows distribution does not appear to contain .c files). However, since I'm not a C programmer, I did not find the .h