Hello

Object's attributes can be created dynamically, ie

class MyClass:
   pass

obj = MyClass()
obj.test = 'foo'

but why doesn't it work with built-in classes int, float, list.... ?

L = [1, 8, 0]
L.test = 'its a list !'

(however lists are mutable, int, float ... are not)

Traceback (most recent call last):
 File "<pyshell#29>", line 1, in <module>
   L.test = 'its a list !'
AttributeError: 'list' object has no attribute 'test'

but it works on functions:

def funct(a,b):
....print(a+b)

funct.test = 'this is a function'

funct.test
'this is a function'

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to