Possible to tack on random stuff to objects?

C

Cruxic

Is it possible to tack on arbitrary attributes to a python object?
For example:

s = 'nice 2 meet you'
s.isFriendly = True

In the above example Python complains on the second line with:

AttributeError: 'str' object has no attribute 'isFriendly'

Is there another way?
 
B

Bruno Desthuilliers

Cruxic a écrit :
Is it possible to tack on arbitrary attributes to a python object?

Depends on the object's class. In the common case it's possible but
there are a couple cases - mostly builtin immutable types - where it's not.
 
C

Cruxic

That does the trick. Thanks, Bruno.

Cruxic a écrit :


Depends on the object's class. In the common case it's possible but
there are a couple cases - mostly builtin immutable types - where it's not..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top