From 283ddc36a55bc25e4e6e4a786d53baf485e79af1 Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Sun, 18 Apr 2021 23:14:58 +0200 Subject: [PATCH] Updated post. --- _posts/2020-07-14-python-3-cheatsheet.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/_posts/2020-07-14-python-3-cheatsheet.md b/_posts/2020-07-14-python-3-cheatsheet.md index 41cd1b7..7600825 100644 --- a/_posts/2020-07-14-python-3-cheatsheet.md +++ b/_posts/2020-07-14-python-3-cheatsheet.md @@ -1,7 +1,7 @@ --- title: Python 3 cheatsheet tags: [python3, python, cheatsheet] -updated: 2020-07-21 17:58 +updated: 2021-04-18 23:10 description: A series of instructions in Python I use frequently on several projects --- @@ -14,6 +14,7 @@ description: A series of instructions in Python I use frequently on several proj - [pathlib](#pathlib) - [Files](#files) - [Paths](#paths) +- [PyYAML](#pyyaml) @@ -21,10 +22,10 @@ description: A series of instructions in Python I use frequently on several proj This is a list of instructions I use frequently in: -- [automated-tasks](https://github.com/frnmst/automated-tasks) -- [fattura-elettronica-reader](https://github.com/frnmst/fattura-elettronica-reader) -- [fpyutils](https://github.com/frnmst/fpyutils) -- [md-toc](https://github.com/frnmst/md-toc) +- [automated-tasks](https://blog.franco.net.eu.org/software/#automated-tasks) +- [fattura-elettronica-reader](https://blog.franco.net.eu.org/software/#fattura-elettronica-reader) +- [fpyutils](https://blog.franco.net.eu.org/software/#fpyutils) +- [md-toc](https://blog.franco.net.eu.org/software/#md-toc) ## pathlib @@ -42,6 +43,12 @@ This is a list of instructions I use frequently in: |-------------|-------------------------------------------------|---------| | get last path component from url | `pathlib.Path(urllib.parse.urlsplit(url: str).path).name` | `import pathlib, urllib` | | get relative path | `pathlib.Path(shlex.quote(path: str)).name` | `import pathlib, shlex` | -| get full path | `str(pathlib.Path(shlex.quote(directory: str), shlex.quote(file: str)))` | `import pathlib, shlex` | +| get full path | `str(pathlib.Path(shlex.quote(directory: str), shlex.quote(file: str)))` | `import pathlib, shlex` | | remove file extension | `pathlib.Path(shlex.quote(path: str)).stem` | `import pathlib, shlex` | | get file extension | `pathlib.Path(shlex.quote(path: str)).suffix` | `import pathlib, shlex` | + +## PyYAML + +| Description | Code | Imports | +|-------------|-------------------------------------------------|---------| +| load a YAML file | `yaml.load(open('a.yaml', 'r'), Loader=yaml.SafeLoader)` | `import yaml` |