Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Licence CC BY-NC-ND Thierry Parmentelat & Arnaud Legout

création de propriétés à la volée

en s’inspirant du code:

Setting: john smith
OOPS property 'name' of 'Person' object has no deleter

écrivez

>>> user = DynamicPerson()
>>> user.addProperty('name')
>>> user.addProperty('phone')
>>> user.name = 'john smith'
Setting: name = john smith
>>> user.phone = '12345'
Setting: phone = 12345
>>> user.name
Getting: name
'John Smith'
>>> user.__dict__
{'_phone': '12345', '_name': 'John Smith'}

indices

Setting: name = john smith
Setting: phone = 12345
Getting: name = john smith
{'_name': 'john smith', '_phone': '12345'}

pour les rapides