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
>
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
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
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
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
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
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
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
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
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
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
11 matches
Mail list logo