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

@ -1,7 +1,7 @@
---
title: Python 3 cheatsheet
tags: [python3, python, cheatsheet]
updated: 2021-04-18 23:10
updated: 2021-04-19 00:13
description: A series of instructions in Python I use frequently on several projects
---
@ -46,9 +46,10 @@ This is a list of instructions I use frequently in:
| 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` |
| get the path of a configuration file | `configuration_file = shlex.quote(sys.argv[1])` | `import shlex, sys` |
## PyYAML
| Description | Code | Imports |
|-------------|-------------------------------------------------|---------|
| load a YAML file | `yaml.load(open('a.yaml', 'r'), Loader=yaml.SafeLoader)` | `import yaml` |
| load a YAML file | `config = yaml.load(open(file: str, 'r'), Loader=yaml.SafeLoader)` | `import yaml` |

Loading…
Cancel
Save