From 153a248a2079358fefe6f38e4d4e7b3f0ba95fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 10 Feb 2019 14:17:22 +0100 Subject: [PATCH] Added memoryview and pathlib --- README.md | 71 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c64e30b..0fba54b 100644 --- a/README.md +++ b/README.md @@ -918,21 +918,6 @@ def write_to_file(filename, text): file.write(text) ``` -### Path -```python -from os import path, listdir - = path.exists() - = path.isfile() - = path.isdir() - = listdir() -``` - -```python ->>> from glob import glob ->>> glob('../*.gif') -['1.gif', 'card.gif'] -``` - ### Command Execution ```python import os @@ -957,6 +942,52 @@ b'.\n..\nfile1.txt\nfile2.txt\n' >>> sys.setrecursionlimit(5000) ``` +### Path +```python +from os import path, listdir + = path.exists() + = path.isfile() + = path.isdir() + = listdir() +``` + +```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('' [, '', , ...]) + = / '' / '' +``` + +```python + = .iterdir() # Returns all files in a dir. + = .glob('') # Returns all matches. + = .resolve() # Makes path absolute. + = .exists() + = .is_dir() + = .open() +``` + +```python + = str() # Returns path as string. + = .name # Final component. + = .stem # Final component without extension. + = .suffix # Final component's extension. + = .parent # Path without final component. + = .parts # All components as strings. +``` + + JSON ---- ```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( / / ) +.release() +``` + + Deque ----- **A thread-safe list with efficient appends and pops from either side. Pronounced “deck”.**