Skip to content

Commit b45b945

Browse files
committed
Duck types, Open, Paths
1 parent 6e3e2a7 commit b45b945

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ Duck Types
10931093
**A duck type is an implicit type that prescribes a set of special methods. Any object that has those methods defined is considered a member of that duck type.**
10941094

10951095
### Comparable
1096-
* **If eq() method is not overridden, it returns `'id(self) == id(other)'`, which is the same as `'self is other'`. That means all user-defined objects compare not equal by default (because id() returns object's memory address that is unique during its lifetime).**
1096+
* **If eq() method is not overridden, it returns `'id(self) == id(other)'`, which is the same as `'self is other'`. That means all user-defined objects compare not equal by default (because id() returns object's memory address that is guaranteed to be unique).**
10971097
* **Only the left side object has eq() method called, unless it returns NotImplemented, in which case the right object is consulted. False is returned if both return NotImplemented.**
10981098
* **Ne() automatically works on any object that has eq() defined.**
10991099

@@ -1591,7 +1591,7 @@ Open
15911591
<str/bytes> = <file>.read(size=-1) # Reads 'size' chars/bytes or until the EOF.
15921592
<str/bytes> = <file>.readline() # Returns a line or empty string/bytes on EOF.
15931593
<list> = <file>.readlines() # Returns remaining lines. Also list(<file>).
1594-
<str/bytes> = next(<file>) # Uses read-ahead buffer. Don't mix with above.
1594+
<str/bytes> = next(<file>) # Returns a line using a read-ahead buffer.
15951595
```
15961596

15971597
```python
@@ -1657,7 +1657,7 @@ from pathlib import Path
16571657

16581658
```python
16591659
<iter> = os.scandir(path='.') # Returns DirEntry objects located at the path.
1660-
<str> = <DirEntry>.path # Returns the whole path (relative by default).
1660+
<str> = <DirEntry>.path # Returns object's path (relative by default).
16611661
<str> = <DirEntry>.name # Returns path's final component as a string.
16621662
<file> = open(<DirEntry>) # Opens the file and returns its file object.
16631663
```

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@
926926
</code></pre></div>
927927

928928
<div><h2 id="ducktypes"><a href="#ducktypes" name="ducktypes">#</a>Duck Types</h2><p><strong>A duck type is an implicit type that prescribes a set of special methods. Any object that has those methods defined is considered a member of that duck type.</strong></p><div><h3 id="comparable">Comparable</h3><ul>
929-
<li><strong>If eq() method is not overridden, it returns <code class="python hljs"><span class="hljs-string">'id(self) == id(other)'</span></code>, which is the same as <code class="python hljs"><span class="hljs-string">'self is other'</span></code>. That means all user-defined objects compare not equal by default (because id() returns object's memory address that is unique during its lifetime).</strong></li>
929+
<li><strong>If eq() method is not overridden, it returns <code class="python hljs"><span class="hljs-string">'id(self) == id(other)'</span></code>, which is the same as <code class="python hljs"><span class="hljs-string">'self is other'</span></code>. That means all user-defined objects compare not equal by default (because id() returns object's memory address that is guaranteed to be unique).</strong></li>
930930
<li><strong>Only the left side object has eq() method called, unless it returns NotImplemented, in which case the right object is consulted. False is returned if both return NotImplemented.</strong></li>
931931
<li><strong>Ne() automatically works on any object that has eq() defined.</strong></li>
932932
</ul><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyComparable</span>:</span>
@@ -1365,7 +1365,7 @@
13651365
<pre><code class="python language-python hljs">&lt;str/bytes&gt; = &lt;file&gt;.read(size=<span class="hljs-number">-1</span>) <span class="hljs-comment"># Reads 'size' chars/bytes or until the EOF.</span>
13661366
&lt;str/bytes&gt; = &lt;file&gt;.readline() <span class="hljs-comment"># Returns a line or empty string/bytes on EOF.</span>
13671367
&lt;list&gt; = &lt;file&gt;.readlines() <span class="hljs-comment"># Returns remaining lines. Also list(&lt;file&gt;).</span>
1368-
&lt;str/bytes&gt; = next(&lt;file&gt;) <span class="hljs-comment"># Uses read-ahead buffer. Don't mix with above.</span>
1368+
&lt;str/bytes&gt; = next(&lt;file&gt;) <span class="hljs-comment"># Returns a line using a read-ahead buffer.</span>
13691369
</code></pre>
13701370
<pre><code class="python language-python hljs">&lt;file&gt;.write(&lt;str/bytes&gt;) <span class="hljs-comment"># Writes a str or bytes object to write buffer.</span>
13711371
&lt;file&gt;.writelines(&lt;collection&gt;) <span class="hljs-comment"># Writes a coll. of strings or bytes objects.</span>
@@ -1408,7 +1408,7 @@
14081408
&lt;num&gt; = &lt;stat&gt;.st_mtime/st_size/… <span class="hljs-comment"># Returns modification time, size in bytes, etc.</span>
14091409
</code></pre>
14101410
<div><h3 id="direntry">DirEntry</h3><p><strong>Unlike listdir(), scandir() returns DirEntry objects that cache isfile, isdir, and on Windows also stat information, thus significantly increasing the performance of code that requires it.</strong></p><pre><code class="python language-python hljs">&lt;iter&gt; = os.scandir(path=<span class="hljs-string">'.'</span>) <span class="hljs-comment"># Returns DirEntry objects located at the path.</span>
1411-
&lt;str&gt; = &lt;DirEntry&gt;.path <span class="hljs-comment"># Returns the whole path (relative by default).</span>
1411+
&lt;str&gt; = &lt;DirEntry&gt;.path <span class="hljs-comment"># Returns object's path (relative by default).</span>
14121412
&lt;str&gt; = &lt;DirEntry&gt;.name <span class="hljs-comment"># Returns path's final component as a string.</span>
14131413
&lt;file&gt; = open(&lt;DirEntry&gt;) <span class="hljs-comment"># Opens the file and returns its file object.</span>
14141414
</code></pre></div>

0 commit comments

Comments
 (0)