You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
***`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `"encoding='utf-8'"` whenever possible.**
1266
+
***`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.**
1267
1267
***`'endline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.**
1268
1268
1269
1269
### Modes
@@ -1318,21 +1318,26 @@ Path
1318
1318
----
1319
1319
```python
1320
1320
from os import path, listdir
1321
+
from glob import glob
1322
+
```
1323
+
1324
+
```python
1321
1325
<bool>= path.exists('<path>')
1322
1326
<bool>= path.isfile('<path>')
1323
1327
<bool>= path.isdir('<path>')
1324
-
<list>= listdir('<path>')
1325
1328
```
1326
1329
1327
1330
```python
1328
-
>>>from glob import glob
1329
-
>>> glob('../*.gif')
1330
-
['1.gif', 'card.gif']
1331
+
<list>= listdir('<path>') # List of filenames located at 'path'.
1332
+
<list>= glob('<pattern>') # Filenames matching the wildcard pattern.
1331
1333
```
1332
1334
1333
1335
### Pathlib
1334
1336
```python
1335
1337
from pathlib import Path
1338
+
```
1339
+
1340
+
```python
1336
1341
cwd = Path()
1337
1342
<Path>= Path('<path>' [, '<path>', <Path>, ...])
1338
1343
<Path>=<Path>/'<dir>'/'<file>'
@@ -1342,11 +1347,11 @@ cwd = Path()
1342
1347
<bool>=<Path>.exists()
1343
1348
<bool>=<Path>.is_file()
1344
1349
<bool>=<Path>.is_dir()
1345
-
<iter>=<Path>.iterdir()
1346
1350
```
1347
1351
1348
1352
```python
1349
-
<iter>=<Path>.glob('<pattern>')
1353
+
<iter>=<Path>.iterdir() # Iterator with filenames located at path.
1354
+
<iter>=<Path>.glob('<pattern>') # Filenames matching the wildcard pattern.
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'encoding=None'</span></code> means default encoding is used, which is platform dependent. Best practice is to use <codeclass="python hljs"><spanclass="hljs-string">"encoding='utf-8'"</span></code> whenever possible.</strong></li>
1147
+
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'encoding=None'</span></code> means default encoding is used, which is platform dependent. Best practice is to use <codeclass="python hljs"><spanclass="hljs-string">'encoding="utf-8"'</span></code> whenever possible.</strong></li>
1148
1148
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'endline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.</strong></li>
1149
1149
</ul>
1150
1150
<h3id="modes">Modes</h3>
@@ -1189,27 +1189,28 @@ <h3 id="writetexttofile">Write Text to File</h3>
<pre><codeclass="python language-python hljs"><list> = listdir(<spanclass="hljs-string">'<path>'</span>) <spanclass="hljs-comment"># List of filenames located at 'path'. </span>
1199
+
<list> = glob(<spanclass="hljs-string">'<pattern>'</span>) <spanclass="hljs-comment"># Filenames matching the wildcard pattern.</span>
<pre><codeclass="python language-python hljs"><iter> = <Path>.iterdir() <spanclass="hljs-comment"># Iterator with filenames located at path.</span>
1213
+
<iter> = <Path>.glob(<spanclass="hljs-string">'<pattern>'</span>) <spanclass="hljs-comment"># Filenames matching the wildcard pattern.</span>
1213
1214
</code></pre>
1214
1215
<pre><codeclass="python language-python hljs"><str> = str(<Path>) <spanclass="hljs-comment"># Returns path as a string.</span>
1215
1216
<tup.> = <Path>.parts <spanclass="hljs-comment"># Returns all components as strings.</span>
0 commit comments