Re: Create a class at run-time

2010-03-26 Thread I V
On Fri, 26 Mar 2010 08:54:11 -0700, Michel wrote: > I want to add a method to a class such that it can be invoked on > specifics instances. > You solution works (as well as Patrick's one), thanks ! I still have a > question though. If I print the type of the self object I get when my > method is >

Re: Create a class at run-time

2010-03-26 Thread Steve Holden
Michel wrote: > Thanks Peter. > > I searched a little bit more and wrote the following example: > > > import types > > class MyClass: > > def test_toto(self): > print type(self) > print self.name > > def test_toto(self): > print type

Re: Create a class at run-time

2010-03-26 Thread Peter Otten
Michel wrote: > Thanks Peter. > > I searched a little bit more and wrote the following example: > > > import types > > class MyClass: > > def test_toto(self): > print type(self) > print self.name > > def test_toto(self): > print typ

Re: Create a class at run-time

2010-03-26 Thread Michel
Thanks Peter. I searched a little bit more and wrote the following example: import types class MyClass: def test_toto(self): print type(self) print self.name def test_toto(self): print type(self) print self.name MyDynClass = typ

Re: Create a class at run-time

2010-03-26 Thread Peter Otten
Michel wrote: > Hi everyone, > > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Here > is what I have so far: > > method_template = "def te

Re: Create a class at run-time

2010-03-26 Thread Michel
I want to add a method to a class such that it can be invoked on specifics instances. You solution works (as well as Patrick's one), thanks ! I still have a question though. If I print the type of the self object I get when my method is called, I get "". I guess this is because the method is define

Re: Create a class at run-time

2010-03-26 Thread Michel
Well, I don't have the reference to the instance. The class is actually instantiated later by a the unittest library. On Mar 25, 6:18 pm, Michiel Overtoom wrote: > On 2010-03-25 23:00, Michel wrote: > > > I'm trying to dynamically create a class. What I need is to define a > > class, add methods

Re: Create a class at run-time

2010-03-25 Thread I V
On Thu, 25 Mar 2010 15:00:35 -0700, Michel wrote: > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods need > to be bound to the instance though, and that's my problem. Here is what > I have so far: I'm not enti

Re: Create a class at run-time

2010-03-25 Thread Patrick Maupin
On Mar 25, 5:00 pm, Michel wrote: > Hi everyone, > > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Here > is what I have so far: Well, you

Re: Create a class at run-time

2010-03-25 Thread Michiel Overtoom
On 2010-03-25 23:00, Michel wrote: I'm trying to dynamically create a class. What I need is to define a class, add methods to it and later instantiate this class. Methods need to be bound to the instance though, and that's my problem. Maybe this snippet is of any help? import functools class

Create a class at run-time

2010-03-25 Thread Michel
Hi everyone, I'm trying to dynamically create a class. What I need is to define a class, add methods to it and later instantiate this class. Methods need to be bound to the instance though, and that's my problem. Here is what I have so far: method_template = "def test_foo(self):\ #actual test