From 9be87dcfa47a05c6a2f846e032375a84ed3f0dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 18 Apr 2018 02:35:03 +0200 Subject: [PATCH] Metaprogramming --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 69aee2b..6b5b5e3 100644 --- a/README.md +++ b/README.md @@ -628,22 +628,22 @@ Introspection and Metaprograming ```python ->>> class B: +>>> class Z: ... def __init__(self): ... self.a = 'abcde' ... self.b = 12345 ->>> b = B() +>>> z = Z() ``` ### Getattr, Hasattr, Setattr ```python ->>> getattr(b, 'a') # Same as B.__getattribute__(b, 'a') +>>> getattr(z, 'a') # Same as Z.__getattribute__(z, 'a') 'abcde' ->>> hasattr(b, 'c') +>>> hasattr(z, 'c') False ->>> setattr(b, 'c', 10) +>>> setattr(z, 'c', 10) ``` ### Type @@ -653,8 +653,8 @@ type(class_name, parents, attributes) ``` ```python ->>> BB = type('B', (), {'a': 'abcde', 'b': 12345}) ->>> b = BB() +>>> Z = type('Z', (), {'a': 'abcde', 'b': 12345}) +>>> z = Z() ``` ### MetaClass