Browse Source

Introspection

pull/99/head
Jure Šorn 3 years ago
parent
commit
05ea5c02dc
2 changed files with 4 additions and 4 deletions
  1. 4
      README.md
  2. 4
      index.html

4
README.md

@ -2141,8 +2141,8 @@ Introspection
### Attributes ### Attributes
```python ```python
<list> = dir(<object>) # Names of object's attributes (incl. methods). <list> = dir(<object>) # Names of object's attributes (incl. methods).
<dict> = vars(<object>) # Dict of object's fields. Also <obj>.__dict__.
<bool> = hasattr(<object>, '<attr_name>') # Checks if getattr() raises an error.
<dict> = vars(<object>) # Dict of writable attrs. Also <obj>.__dict__.
<bool> = hasattr(<object>, '<attr_name>') # Checks if getattr() raises an AttributeError.
value = getattr(<object>, '<attr_name>') # Raises AttributeError if attribute is missing. value = getattr(<object>, '<attr_name>') # Raises AttributeError if attribute is missing.
setattr(<object>, '<attr_name>', value) # Only works on objects with __dict__ attribute. setattr(<object>, '<attr_name>', value) # Only works on objects with __dict__ attribute.
delattr(<object>, '<attr_name>') # Equivalent to `del <object>.<attr_name>`. delattr(<object>, '<attr_name>') # Equivalent to `del <object>.<attr_name>`.

4
index.html

@ -1905,8 +1905,8 @@ last_el = op.methodcaller(<span class="hljs-string">'pop'</span>)(&lt;l
<div><h3 id="attributes-1">Attributes</h3><pre><code class="python language-python hljs">&lt;list&gt; = dir(&lt;object&gt;) <span class="hljs-comment"># Names of object's attributes (incl. methods).</span> <div><h3 id="attributes-1">Attributes</h3><pre><code class="python language-python hljs">&lt;list&gt; = dir(&lt;object&gt;) <span class="hljs-comment"># Names of object's attributes (incl. methods).</span>
&lt;dict&gt; = vars(&lt;object&gt;) <span class="hljs-comment"># Dict of object's fields. Also &lt;obj&gt;.__dict__.</span>
&lt;bool&gt; = hasattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Checks if getattr() raises an error.</span>
&lt;dict&gt; = vars(&lt;object&gt;) <span class="hljs-comment"># Dict of writable attrs. Also &lt;obj&gt;.__dict__.</span>
&lt;bool&gt; = hasattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Checks if getattr() raises an AttributeError.</span>
value = getattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Raises AttributeError if attribute is missing.</span> value = getattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Raises AttributeError if attribute is missing.</span>
setattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>, value) <span class="hljs-comment"># Only works on objects with __dict__ attribute.</span> setattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>, value) <span class="hljs-comment"># Only works on objects with __dict__ attribute.</span>
delattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Equivalent to `del &lt;object&gt;.&lt;attr_name&gt;`.</span> delattr(&lt;object&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Equivalent to `del &lt;object&gt;.&lt;attr_name&gt;`.</span>

Loading…
Cancel
Save