virtualenv venv
. venv/bin/activate
pip install --editable .
You want to really understand decorators? Watch this video!
boilerplate:
import functools
def decorator(func):
@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
# Do something before
value = func(*args, **kwargs)
# Do something after
return value
return wrapper_decorator
When you want to publish a beta version, you can use a special tag that won't be proposed to client using pip install package --upgrade
example :
current version = 3.0.1
next version = 3.1.0
I can tag with 3.1.0-alpha.1
pip install --upgrade won't upgrade to this version but pip install package==3.1.0-alpha.1 will
django template does not like defaultdict, 2 solutions:
1) set default_factory to None
or
2) cast defaultdict to a simpledict
"The template variable resolution algorithm in Django will attempt to resolve new_data.items as new_data['items'] first, which resolves to an empty list when using defaultdict(list)."
# filter out all elements not with x > 5
a = [el for el in data if el['x'] > 5]
# get all the 'c' attributes as a list
b = [el['c'] for el in data]
# get all the 'c' attributes for the elements with x > 5
c = [el['c'] for el in data if el['x'] > 5]
In Jinja2:
a: {{ data | selectattr('x', 'gt', 5) | list }}
b: {{ data | map(attribute='c') | list }}
c: {{ data | selectattr('x', 'gt', 5) | map(attribute='c') | list }}
Ce truc obscur qui t'arrive et où la solution se trouve au fond d'une PR
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
python dependency management with lock file
++++++++++++++++++++++
Version avec interface cmd
++++++++++++++++++++++
Prérequis :
pip install pudb
Pour docker, dans le docker compose ajouter
stdin_open: true
tty: true
Faire docker attach container_name
Comment break/debug :
Là où on veut break, il suffit de coller cette ligne : import pudb; pu.db
Dans le terminal où on a fait docker attach on doit voir l'interface de pudb
++++++++++++++++++++++
Version + simple
++++++++++++++++++++++
Prérequis : python 3.7
Pour docker, dans le docker compose ajouter
stdin_open: true
tty: true
Faire docker attach container_name
Comment break/debug :
breakpoint()
Dans le terminal où on a fait docker attach on doit voir un prompt
On peut print les variables
"continue" pour continuer