Browse Source

Added memoryview and pathlib

pull/22/head
Jure Šorn 6 years ago
parent
commit
153a248a20
1 changed files with 56 additions and 15 deletions
  1. 71
      README.md

71
README.md

@ -918,21 +918,6 @@ def write_to_file(filename, text):
file.write(text) file.write(text)
``` ```
### Path
```python
from os import path, listdir
<bool> = path.exists(<path>)
<bool> = path.isfile(<path>)
<bool> = path.isdir(<path>)
<list> = listdir(<path>)
```
```python
>>> from glob import glob
>>> glob('../*.gif')
['1.gif', 'card.gif']
```
### Command Execution ### Command Execution
```python ```python
import os import os
@ -957,6 +942,52 @@ b'.\n..\nfile1.txt\nfile2.txt\n'
>>> sys.setrecursionlimit(5000) >>> sys.setrecursionlimit(5000)
``` ```
### Path
```python
from os import path, listdir
<bool> = path.exists(<path>)
<bool> = path.isfile(<path>)
<bool> = path.isdir(<path>)
<list> = listdir(<path>)
```
```python
>>> from glob import glob
>>> glob('../*.gif')
['1.gif', 'card.gif']
```
Pathlib
-------
**This module offers classes representing filesystem paths with semantics appropriate for different operating systems.**
```python
from pathlib import Path
pwd = Path()
<Path> = Path('<path>' [, '<path>', <Path>, ...])
<Path> = <Path> / '<dir>' / '<file>'
```
```python
<iter> = <Path>.iterdir() # Returns all files in a dir.
<iter> = <Path>.glob('<pattern>') # Returns all matches.
<Path> = <Path>.resolve() # Makes path absolute.
<bool> = <Path>.exists()
<bool> = <Path>.is_dir()
<file> = <Path>.open()
```
```python
<str> = str(<Path>) # Returns path as string.
<str> = <Path>.name # Final component.
<str> = <Path>.stem # Final component without extension.
<str> = <Path>.suffix # Final component's extension.
<Path> = <Path>.parent # Path without final component.
<tuple> = <Path>.parts # All components as strings.
```
JSON JSON
---- ----
```python ```python
@ -1121,6 +1152,16 @@ from array import array
``` ```
Memory View
-----------
**Used for accessing the internal data of an object that supports the buffer protocol.**
```python
<memoryview> = memoryview(<bytes> / <bytearray> / <array>)
<memoryview>.release()
```
Deque Deque
----- -----
**A thread-safe list with efficient appends and pops from either side. Pronounced “deck”.** **A thread-safe list with efficient appends and pops from either side. Pronounced “deck”.**

Loading…
Cancel
Save