|
1437 | 1437 | </ul><div><h3 id="fileobject">File Object</h3><pre><code class="python language-python hljs"><file>.seek(<span class="hljs-number">0</span>) <span class="hljs-comment"># Moves to the start of the file.</span>
|
1438 | 1438 | <file>.seek(offset) <span class="hljs-comment"># Moves 'offset' chars/bytes from the start.</span>
|
1439 | 1439 | <file>.seek(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Moves to the end of the file.</span>
|
1440 |
| -<bin_file>.seek(±offset, <anchor>) <span class="hljs-comment"># Anchor: 0 start, 1 current pos., 2 end.</span> |
| 1440 | +<bin_file>.seek(±offset, <anchor>) <span class="hljs-comment"># Anchor: 0 start, 1 current position, 2 end.</span> |
1441 | 1441 | </code></pre></div></div></div>
|
1442 | 1442 |
|
1443 | 1443 |
|
|
1527 | 1527 | <pre><code class="python language-python hljs">os.chdir(<path>) <span class="hljs-comment"># Changes the current working directory.</span>
|
1528 | 1528 | os.mkdir(<path>, mode=<span class="hljs-number">0o777</span>) <span class="hljs-comment"># Creates a directory. Mode is in octal.</span>
|
1529 | 1529 | </code></pre>
|
1530 |
| -<pre><code class="python language-python hljs">shutil.copy(from, to) <span class="hljs-comment"># Copies the file. 'to' can be a directory.</span> |
| 1530 | +<pre><code class="python language-python hljs">shutil.copy(from, to) <span class="hljs-comment"># Copies the file. 'to' can exist or be a dir.</span> |
1531 | 1531 | shutil.copytree(from, to) <span class="hljs-comment"># Copies the directory. 'to' must not exist.</span>
|
1532 | 1532 | </code></pre>
|
1533 | 1533 | <pre><code class="python language-python hljs">os.rename(from, to) <span class="hljs-comment"># Renames/moves the file or directory.</span>
|
|
1541 | 1541 | <str> = os.popen(<span class="hljs-string">'<shell_command>'</span>).read()
|
1542 | 1542 | </code></pre></div>
|
1543 | 1543 |
|
1544 |
| -<div><h4 id="sends11tothecalculatorandcapturesitsoutput">Sends '1 + 1' to the calculator and captures its output:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> subprocess <span class="hljs-keyword">import</span> run |
| 1544 | +<div><h4 id="sends11tothebasiccalculatorandcapturesitsoutput">Sends '1 + 1' to the basic calculator and captures its output:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> subprocess <span class="hljs-keyword">import</span> run |
1545 | 1545 | <span class="hljs-meta">>>> </span>run(<span class="hljs-string">'bc'</span>, input=<span class="hljs-string">'1 + 1\n'</span>, capture_output=<span class="hljs-keyword">True</span>, encoding=<span class="hljs-string">'utf-8'</span>)
|
1546 | 1546 | CompletedProcess(args=<span class="hljs-string">'bc'</span>, returncode=<span class="hljs-number">0</span>, stdout=<span class="hljs-string">'2\n'</span>, stderr=<span class="hljs-string">''</span>)
|
1547 | 1547 | </code></pre></div>
|
1548 | 1548 |
|
1549 |
| -<div><h4 id="sendstestintothecalculatorrunninginstandardmodeandsavesitsoutputtotestout">Sends test.in to the calculator running in standard mode and saves its output to test.out:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> shlex <span class="hljs-keyword">import</span> split |
| 1549 | +<div><h4 id="sendstestintothebasiccalculatorrunninginstandardmodeandsavesitsoutputtotestout">Sends test.in to the basic calculator running in standard mode and saves its output to test.out:</h4><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> shlex <span class="hljs-keyword">import</span> split |
1550 | 1550 | <span class="hljs-meta">>>> </span>os.popen(<span class="hljs-string">'echo 1 + 1 > test.in'</span>)
|
1551 | 1551 | <span class="hljs-meta">>>> </span>run(split(<span class="hljs-string">'bc -s'</span>), stdin=open(<span class="hljs-string">'test.in'</span>), stdout=open(<span class="hljs-string">'test.out'</span>, <span class="hljs-string">'w'</span>))
|
1552 | 1552 | CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs-string">'-s'</span>], returncode=<span class="hljs-number">0</span>)
|
|
1604 | 1604 | </code></pre></div>
|
1605 | 1605 |
|
1606 | 1606 | <ul>
|
1607 |
| -<li><strong>File must be opened with <code class="python hljs"><span class="hljs-string">'newline=""'</span></code> argument, or an extra '\r' will be added to every '\n' on platforms that use '\r\n' line endings!</strong></li> |
| 1607 | +<li><strong>File must be opened with <code class="python hljs"><span class="hljs-string">'newline=""'</span></code> argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!</strong></li> |
1608 | 1608 | </ul>
|
1609 | 1609 | <div><h3 id="parameters">Parameters</h3><ul>
|
1610 | 1610 | <li><strong><code class="python hljs"><span class="hljs-string">'dialect'</span></code> - Master parameter that sets the default values.</strong></li>
|
|
0 commit comments