From bc3f5659576aa0d2803a4cd933079b1393537be5 Mon Sep 17 00:00:00 2001 From: neodarz Date: Thu, 14 Feb 2019 12:46:55 +0100 Subject: Update some tips --- cheat/.cheat/python | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cheat/.cheat/python') diff --git a/cheat/.cheat/python b/cheat/.cheat/python index e4f5d36..4428b48 100644 --- a/cheat/.cheat/python +++ b/cheat/.cheat/python @@ -17,3 +17,28 @@ python -mjson.tool # Generate requirements.txt pipreqs /path/to/project + +# Tips +# Ressources available in : cheat python_ressources + +Input: décoder avec `decode()`. +Output: encoder avec `encode('utf-8')` + +lors de l'ouverture d'un fichier: +``` +from codecs import open + +# open() de codec à exactement la même API, y compris avec "with" +f = open('fichier', encoding='encoding') +``` + +# Types + +bytes == bytearray + +# non mutable (non modifiable) +bytes +tuple + +# mutable (modifiable) +bytearray -- cgit v1.2.1