Skip to content

Commit e40d97c

Browse files
committed
Attributes
1 parent 83a6ee2 commit e40d97c

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

README.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,25 +1391,10 @@ Introspection and Metaprograming
13911391

13921392
### Attributes
13931393
```python
1394-
class Z:
1395-
def __init__(self):
1396-
self.a = 'abcde'
1397-
self.b = 12345
1398-
```
1399-
1400-
```python
1401-
>>> z = Z()
1402-
1403-
>>> vars(z)
1404-
{'a': 'abcde', 'b': 12345}
1405-
1406-
>>> getattr(z, 'a')
1407-
'abcde'
1408-
1409-
>>> hasattr(z, 'c')
1410-
False
1411-
1412-
>>> setattr(z, 'c', 10)
1394+
<dict> = vars(<object>)
1395+
<bool> = hasattr(<object>, '<attr_name>')
1396+
value = getattr(<object>, '<attr_name>')
1397+
setattr(<object>, '<attr_name>', value)
14131398
```
14141399

14151400
### Parameters

0 commit comments

Comments
 (0)