Adding attribute to object

John Roth newsgroups at jhrothjr.com
Wed Dec 3 20:01:24 EST 2003


"marco" <marc.lentz at ctrceal.caisse-epargne.fr> wrote in message
news:bql1gc$r9c$2 at s1.read.news.oleane.net...
> hi
>
> I've got a class "myClass" ... and i CAN'T EXTENDS this class!
> But i can add NEW methods to "myClass", like that :
>
> method = new.instancemethod( myNewMethod , None, myClass)
> myClass.__dict__[method.__name__] = method
>
> i'd like to add NEW attributs to "myClass" ...
> i'm pretty sure it's possible (with "get/set-attr") ... but i don't know
how
> to do that
> in fact, i'd like to wrap an newAttribut to an existingAttribut ...
> can anyone drop me 3 lines on how to do that ?

I'm not at all sure what you're trying to do, since new. simply
isn't necessary.

if you have a class

class FooBar(object):
    pass

and you want to add an attribute to it, just do it.

FooBar.newAttr = "Hi, There."

Of course, Jay O'Connor is also correct - why would you
want to do that? (There are reasons why you might, it just
doesn't seem like a novice type thing to do.)

John Roth
>
>
>
>






More information about the Python-list mailing list