Table des matières

,

Brouillon - Python

Python

Debug

https://www.youtube.com/watch?v=HHrVBKZLolg

V env

https://sametmax.com/les-environnement-virtuels-python-virtualenv-et-virtualenvwrapper/

Basic

https://sametmax.com/trier-un-csv-de-5-go/

Assert https://sametmax.com/programmation-par-contrat-avec-assert/

[expression for element in sequence]

[element.upper() for element in sequence] print(['a' * nombre for nombre in sequence]) sequence = [(nombre, list(range(nombre))) for nombre in sequence]

if is_ok:
    print(welcome)
else:
    print(error)
 
print(welcome if is_ok else error)

String

Source : /usr/share/apport/package-hooks/source_apparmor.py

import codecs
 
 
def stringify(s):
    '''Converts a byte array into a unicode string'''
    return codecs.latin_1_decode(s)[0]

lambda

https://www.journaldev.com/37089/how-to-compare-two-lists-in-python https://realpython.com/python-lambda/

Other module

from itertools import groupby from collections import defaultdict

Doc

pydoc  en format texte python3 -m pydoc mon_module python3 -m pydoc mon_module.ma_fonction  en format html python3 -m pydoc -w mon_module python3 -m pydoc -w mon_module.ma_fonction

IPython

python3 -m IPython

POO

https://marshmallow.readthedocs.io/en/latest/

Les dataclasses

Voir https://sametmax.com/python-3-7-sort-de-sa-coquille/

from dataclasses import dataclass
 
@dataclass
class Achat:
    produit: str
    prix: float
    quantite: int = 0
 

Trio

https://sametmax.com/super-article-invite-sur-trio-que-lauteur-a-oublie-de-titrer/

Linter / Formater

https://sametmax.com/once-you-go-black-you-never-go-back/ https://linuxfr.org/news/python-partie-9-formateur-de-code-analyse-statique

IDE

https://sametmax.com/je-fais-mon-coming-out/

Autres

import sys
import math
from contextlib import redirect_stdout
 
 
def compute_join_point(s_1, s_2):
    # Write your code here
    # To debug: print("Debug messages...", file=sys.stderr, flush=True)
 
    return 0
 
# Ignore and do not change the code below
def main():
    s_1 = int(input())
    s_2 = int(input())
    with redirect_stdout(sys.stderr):
        res = compute_join_point(s_1, s_2)
    print(res)
 
if __name__ == "__main__":
    main()
 
import sys
import math
from contextlib import redirect_stdout
 
 
def find_network_endpoint(start_node_id, from_ids, to_ids):
    # Write your code here
    # To debug: print("Debug messages...", file=sys.stderr, flush=True)
 
    return 0
 
# Ignore and do not change the code below
def main():
    start_node_id = int(input())
    n = int(input())
    #from_ids = [int(i) for i in input().split()]
    #to_ids = [int(i) for i in input().split()]
    from_ids = [1 7 3 4 2 6 9]
    to_ids = [3 3 4 6 6 9 5]
    with redirect_stdout(sys.stderr):
        endPointId = find_network_endpoint(start_node_id, from_ids, to_ids)
    print(end_point_id)
 
if __name__ == "__main__":
    main()
 
1 7 3 4 2 6 9
3 3 4 6 6 9 5
--------------------------

Touch file

open(new_file_path, "wb").close()  # create new file in working tree