* **`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.**
* **`'newline=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.**
* **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.**
* **`'newline=""'` means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.**
### Modes
@ -1570,8 +1570,8 @@ from glob import glob
```
```python
<list> = listdir('<path>') # List of filenames located at path.
<list> = glob('<pattern>') # Filenames matching the wildcard pattern.
<list> = listdir('<path>') # List of filenames located at path.
<list> = glob('<pattern>') # Filenames matching the wildcard pattern.
```
### Pathlib
@ -1592,22 +1592,22 @@ cwd = Path()
```
```python
<iter> = <Path>.iterdir() # Returns dir contents as Path objects.
<iter> = <Path>.glob('<pattern>') # Returns Paths matching the wildcard pattern.
<iter> = <Path>.iterdir() # Returns dir contents as Path objects.
<iter> = <Path>.glob('<pattern>') # Returns Paths matching the wildcard pattern.
```
```python
<str> = str(<Path>) # Path as a string.
<str> = <Path>.name # Final component.
<str> = <Path>.stem # Final component without extension.
<str> = <Path>.suffix # Final component's extension.
<tup.> = <Path>.parts # All components as strings.
<str> = str(<Path>) # Path as a string.
<str> = <Path>.name # Final component.
<str> = <Path>.stem # Final component without extension.
<str> = <Path>.suffix # Final component's extension.
<tup.> = <Path>.parts # All components as strings.
```
```python
<Path> = <Path>.resolve() # Returns absolute path without symlinks.
<Path> = <Path>.parent # Returns path without final component.
<file> = open(<Path>) # Opens the file and returns a file object.
<Path> = <Path>.resolve() # Returns absolute path without symlinks.
<Path> = <Path>.parent # Returns path without final component.
<file> = open(<Path>) # Opens the file and returns a file object.
```
@ -1622,29 +1622,29 @@ import os, shutil
```
```python
os.chdir(<path>) # Changes current working directory.
os.mkdir(<path>, mode=0o777) # Creates a directory.
os.chdir(<path>) # Changes current working directory.
os.mkdir(<path>, mode=0o777) # Creates a directory.
```
```python
os.rename(from, to) # Renames the file or directory.
os.replace(from, to) # Same, but overwrites 'to' if it exists.
os.rename(from, to) # Renames the file or directory.
os.replace(from, to) # Same, but overwrites 'to' if it exists.
```
```python
os.remove(<path>) # Deletes the file.
os.rmdir(<path>) # Deletes empty directory.
shutil.rmtree(<path>) # Deletes the entire directory tree.
os.remove(<path>) # Deletes the file.
os.rmdir(<path>) # Deletes empty directory.
shutil.rmtree(<path>) # Deletes the entire directory tree.
```
```python
shutil.copy(from, to) # Copies the file.
shutil.copytree(from, to) # Copies the entire directory tree.
shutil.copy(from, to) # Copies the file.
shutil.copytree(from, to) # Copies the entire directory tree.
```
```python
<str> = os.getcwd() # Returns the current working directory.
<iter> = os.scandir(path='.') # Returns os.DirEntry objects located at path.
<str> = os.getcwd() # Returns the current working directory.
<iter> = os.scandir(path='.') # Returns os.DirEntry objects located at path.
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'default=<el>'</span></code> to set the default value.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'type=FileType(<mode>)'</span></code> for files.</strong></li>
</ul>
<div><h2id="open"><ahref="#open"name="open">#</a>Open</h2><p><strong>Opens a file and returns a corresponding file object.</strong></p><pre><codeclass="python language-python hljs"><file> = open(<spanclass="hljs-string">'<path>'</span>, mode=<spanclass="hljs-string">'r'</span>, encoding=<spanclass="hljs-keyword">None</span>, newline=<spanclass="hljs-keyword">None</span>)
<div><h2id="open"><ahref="#open"name="open">#</a>Open</h2><p><strong>Opens the file and returns a corresponding file object.</strong></p><pre><codeclass="python language-python hljs"><file> = open(<spanclass="hljs-string">'<path>'</span>, mode=<spanclass="hljs-string">'r'</span>, encoding=<spanclass="hljs-keyword">None</span>, newline=<spanclass="hljs-keyword">None</span>)
</code></pre></div>
<ul>
<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>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=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>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=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 the system's default line separator.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=""'</span></code> means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.</strong></li>
<pre><codeclass="python language-python hljs"><list> = listdir(<spanclass="hljs-string">'<path>'</span>) <spanclass="hljs-comment"># List of filenames located at path.</span>
<list> = glob(<spanclass="hljs-string">'<pattern>'</span>) <spanclass="hljs-comment"># Filenames matching the wildcard pattern.</span>
<pre><codeclass="python language-python hljs"><list> = listdir(<spanclass="hljs-string">'<path>'</span>) <spanclass="hljs-comment"># List of filenames located at path.</span>
<list> = glob(<spanclass="hljs-string">'<pattern>'</span>) <spanclass="hljs-comment"># Filenames matching the wildcard pattern.</span>