Skip to content

Commit 153a248

Browse files
committed
Added memoryview and pathlib
1 parent e440bcf commit 153a248

File tree

1 file changed

+56
-15
lines changed

1 file changed

+56
-15
lines changed

README.md

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -918,21 +918,6 @@ def write_to_file(filename, text):
918918
file.write(text)
919919
```
920920

921-
### Path
922-
```python
923-
from os import path, listdir
924-
<bool> = path.exists(<path>)
925-
<bool> = path.isfile(<path>)
926-
<bool> = path.isdir(<path>)
927-
<list> = listdir(<path>)
928-
```
929-
930-
```python
931-
>>> from glob import glob
932-
>>> glob('../*.gif')
933-
['1.gif', 'card.gif']
934-
```
935-
936921
### Command Execution
937922
```python
938923
import os
@@ -957,6 +942,52 @@ b'.\n..\nfile1.txt\nfile2.txt\n'
957942
>>> sys.setrecursionlimit(5000)
958943
```
959944

945+
### Path
946+
```python
947+
from os import path, listdir
948+
<bool> = path.exists(<path>)
949+
<bool> = path.isfile(<path>)
950+
<bool> = path.isdir(<path>)
951+
<list> = listdir(<path>)
952+
```
953+
954+
```python
955+
>>> from glob import glob
956+
>>> glob('../*.gif')
957+
['1.gif', 'card.gif']
958+
```
959+
960+
961+
Pathlib
962+
-------
963+
**This module offers classes representing filesystem paths with semantics appropriate for different operating systems.**
964+
965+
```python
966+
from pathlib import Path
967+
pwd = Path()
968+
<Path> = Path('<path>' [, '<path>', <Path>, ...])
969+
<Path> = <Path> / '<dir>' / '<file>'
970+
```
971+
972+
```python
973+
<iter> = <Path>.iterdir() # Returns all files in a dir.
974+
<iter> = <Path>.glob('<pattern>') # Returns all matches.
975+
<Path> = <Path>.resolve() # Makes path absolute.
976+
<bool> = <Path>.exists()
977+
<bool> = <Path>.is_dir()
978+
<file> = <Path>.open()
979+
```
980+
981+
```python
982+
<str> = str(<Path>) # Returns path as string.
983+
<str> = <Path>.name # Final component.
984+
<str> = <Path>.stem # Final component without extension.
985+
<str> = <Path>.suffix # Final component's extension.
986+
<Path> = <Path>.parent # Path without final component.
987+
<tuple> = <Path>.parts # All components as strings.
988+
```
989+
990+
960991
JSON
961992
----
962993
```python
@@ -1121,6 +1152,16 @@ from array import array
11211152
```
11221153

11231154

1155+
Memory View
1156+
-----------
1157+
**Used for accessing the internal data of an object that supports the buffer protocol.**
1158+
1159+
```python
1160+
<memoryview> = memoryview(<bytes> / <bytearray> / <array>)
1161+
<memoryview>.release()
1162+
```
1163+
1164+
11241165
Deque
11251166
-----
11261167
**A thread-safe list with efficient appends and pops from either side. Pronounced “deck”.**

0 commit comments

Comments
 (0)