Browse Source

Updated post.

dev
Franco Masotti 1 year ago
parent
commit
283ddc36a5
Signed by: frnmst
GPG Key ID: 24116ED85666780A
  1. 19
      _posts/2020-07-14-python-3-cheatsheet.md

19
_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)
<!--TOC-->
@ -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` |

Loading…
Cancel
Save