Browse Source

Attributes

pull/27/head
Jure Šorn 6 years ago
parent
commit
e40d97c538
1 changed files with 4 additions and 19 deletions
  1. 23
      README.md

23
README.md

@ -1391,25 +1391,10 @@ Introspection and Metaprograming
### Attributes ### Attributes
```python ```python
class Z: <dict> = vars(<object>)
def __init__(self): <bool> = hasattr(<object>, '<attr_name>')
self.a = 'abcde' value = getattr(<object>, '<attr_name>')
self.b = 12345 setattr(<object>, '<attr_name>', value)
```
```python
>>> z = Z()
>>> vars(z)
{'a': 'abcde', 'b': 12345}
>>> getattr(z, 'a')
'abcde'
>>> hasattr(z, 'c')
False
>>> setattr(z, 'c', 10)
``` ```
### Parameters ### Parameters

|||||||
100:0
Loading…
Cancel
Save