\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{B4LBU} \pdfinfo{ /Title (python-3.pdf) /Creator (Cheatography) /Author (B4LBU) /Subject (Python 3 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1D14A3} \definecolor{LightBackground}{HTML}{F0F0F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Python 3 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{B4LBU} via \textcolor{DarkBackground}{\uline{cheatography.com/146469/cs/31689/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}B4LBU \\ \uline{cheatography.com/b4lbu} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 14th April, 2022.\\ Updated 14th April, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{commentaire}} \tn % Row 0 \SetRowColor{LightBackground} \# commentaire & commentaire simple \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} """\{\{nl\}\} docstring \{\{nl\}\}""" & commentaire de type docstring, appellable avec help() \tn % Row Count 4 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{string method}} \tn % Row 0 \SetRowColor{LightBackground} capitalize() & 1 lettre en majuscule et reste en minuscule \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} find(model) & renvoie le plus petit index où model est dans la string \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} isalnum() & True si string est alphanumérique \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} isdecimal() & True si string est un décimal \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} isdigit() & True si strind est en digit \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} islower() & True si string est en minuscule \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} isupper() & True si toute la string est en majuscule \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{'.'.join(itérable)} & crée une string à partir d'un itérable et le '.' est le séparateur entre chaque élément de la nouvelle string \tn % Row Count 20 (+ 5) % Row 8 \SetRowColor{LightBackground} lower() & returne un copie de la string en minuscule \tn % Row Count 22 (+ 2) % Row 9 \SetRowColor{white} upper() & retourne une copie de la string en majuscule \tn % Row Count 24 (+ 2) % Row 10 \SetRowColor{LightBackground} replace(old, new, count=-1) & retourne unen copie de la string avec les old remplacé par new, count correspond au nombre maximum de remplacement. -1 remplace toutes les occurences \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{string method (cont)}} \tn % Row 11 \SetRowColor{LightBackground} split(sep=None) & retourne une list des mots de la string, si sep = '', la liste contient tous les caractères \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.48 cm} x{5.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{slicing}} \tn % Row 0 \SetRowColor{LightBackground} str{[}init:end:step{]} & init est le début de la liste, par défaut 0, end est la fin voulue et step est le pas, par defaut 1. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} str{[}::-1{]} & renvoie la string à l'envert \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.48 cm} x{5.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{f-string}} \tn % Row 0 \SetRowColor{LightBackground} f"\{var\} text" & retourne la valeur de la variable accompagnée du text \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \{:\textless{}6\} \{:\textgreater{}6\} \{:\textasciicircum{}6\} & aligné à gauche, droite ou centré sur 6 caractères, possibilité d'ajouter un caractère pour remplir les emplacements vides \tn % Row Count 7 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{4 cm} p{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{changement de base}} \tn % Row 0 \SetRowColor{LightBackground} bin() & 0b... \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} oct() & 0o... \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} hex() & 0x... \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} int() & ... \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{vrac \& tips}} \tn % Row 0 \SetRowColor{LightBackground} while (var := input()) \textgreater{} ... & permet d'affecter une valeur au sein d'une expression plus large. Le input ainsi que le while est un exemple \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \$ pydoc3 -w /chemin\_du\_script & génere un fichier html avec la pydoc \tn % Row Count 8 (+ 2) % Row 2 \SetRowColor{LightBackground} subprocess.run({[}"commande\_bash", argument{]}) & avec import subprocess pour executer une commande bash \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{fonction}} \tn % Row 0 \SetRowColor{LightBackground} def def (param1, param2, ...):\{\{nl\}\}~~~~commande\{\{nl\}\}~~~~commande\{\{nl\}\}~~~~return val & definition globale d'une fonction \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} def f(a, b, /, **kwargs): & avant le / le paramêtre est exclusivement positionnel \tn % Row Count 11 (+ 3) % Row 2 \SetRowColor{LightBackground} var = lambda traitement & la lambda est une fonction anonyme qui ne retourn pas de valeur car le traitement est envoyé dans un variable \tn % Row Count 17 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{regex}} \tn % Row 0 \SetRowColor{LightBackground} import re & module re \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{re.search(model}, string) & renvoie les occurences du model dans la string \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} re.match(model, str) & cherche si le début de la chaîne correspond \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{re.fullmatch(model}, str) & si l'entièreté de la chaîne correspond \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{re.findall(model}, str) & ressence toutes les occurances sous la forme d'une liste \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{re.finditer(regex}, str) & produit le même résultat que findall mais sous forme d'un itérateur \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} re.split(model, str) & créer une liste à partir d'une chaîne de caractères en utilisant un modèle comme séparateur \tn % Row Count 18 (+ 5) % Row 7 \SetRowColor{white} re.sub(model, elem, str) & remplace le model de str par elem \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{sauvegarde de donnée}} \tn % Row 0 \SetRowColor{LightBackground} import csv & module csv qui permet de traiter facilement les csv \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} writer = \seqsplit{csv.writer(file)} & writer est un objet qui gère l'écriture \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{writer.writerow(entete)} & entête est une liste \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{writer.writerows(data)} & data est une liste de liste (autant de ligne que de liste dans data \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} reader = \seqsplit{csv.reader(file)} & itérable permetant la lecture d'un fichier csv. next(reader) permet de sauter une ligne du reader \tn % Row Count 15 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{P.O.O}} \tn % Row 0 \SetRowColor{LightBackground} class Maclasse: & definit ma classe \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} class B(A): & la classe B hérite de A \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} def \_\_init\_\_ (self, parm ...): & permet de créer une methode d'initialisation de la classe \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} @classmethod\{\{nl\}\}def class\_(cls): & methode disponible pour l'ensemble de la classe, cls représente la classe \tn % Row Count 10 (+ 4) % Row 4 \SetRowColor{LightBackground} def instance\_(self): & methode applicable uniquement à l'instance, self représente l'instance \tn % Row Count 14 (+ 4) % Row 5 \SetRowColor{white} if \_\_name\_\_ == '\_\_main\_\_': & les commandes de se blocs sont jouées si le nom main est le nom actuel du programme \tn % Row Count 19 (+ 5) % Row 6 \SetRowColor{LightBackground} \seqsplit{super().\_\_init\_\_(param}, ...) & dans le cadre de l'héritage, super() représente le parent au sein de la classe enfant \tn % Row Count 24 (+ 5) % Row 7 \SetRowColor{white} @property & permet d'accéder à la valeur d'un attribut privé \tn % Row Count 27 (+ 3) % Row 8 \SetRowColor{LightBackground} @\textless{}nom\_du\_getter\textgreater{}.setter & modifier la valeur d'un attribut privé \tn % Row Count 29 (+ 2) % Row 9 \SetRowColor{white} public : nom / protected : \_nom / private : \_\_nom & encapsulation : restreindre l'accès des données entres elles \tn % Row Count 33 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{list method}} \tn % Row 0 \SetRowColor{LightBackground} append() & ajoute un élément à la fin de la liste \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} clear() & retire tous les éléments de la liste \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} count(value) & retourne le nombre d'occurence de value \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{extend(iterable)} & agrandit la liste en ajoutant les éléments d'un itérable \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} insert(index, object) & insert l'objet avant l'index voulu \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{pop(index=-1)} & retire par defaut le dernier élément de la liste. IndexError si la liste est vide \tn % Row Count 15 (+ 4) % Row 6 \SetRowColor{LightBackground} index(value) & retourne le premier index de value. ValueError si value n'est pas dans la liste \tn % Row Count 19 (+ 4) % Row 7 \SetRowColor{white} \seqsplit{remove(value)} & retire la première occurance de value. ValueError si elle n'est pas présente \tn % Row Count 22 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{sort(reverse=False)} & retourn la liste triée (mais ne modifie pas la liste) \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.36 cm} x{6.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{dict method}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{clear()} & retire tous les éléments du dictionnaire \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{get(key)} & retourne la valeur associé à key, sinon None \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{items()} & objet donnant une view du dictionnaire \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{keys()} & view de toutes les keys du dictionnaire \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{values()} & objet donnant une view des valeur du dictionnaire \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{compréhentions}} \tn % Row 0 \SetRowColor{LightBackground} {[} var for var in itérable {]} & crée une nouvelle liste \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {[}int(i) for i in range(21) if i\%2 == 0{]} & exemple avec une liste des 20 premier nombre pair \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \{k: v for k, v in zip(liste1, liste2)\} & dictionnaire (usage du zip) \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{structure de test}} \tn % Row 0 \SetRowColor{LightBackground} if condition :\{\{nl\}\}~~~~instruction\{\{nl\}\}elif condition :\{\{nl\}\}~~~~instruction\{\{nl\}\}else :\{\{nl\}\}~~~~instruction & structure classique \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} valeur = val\_vrai if condition else val\_faux & structure ternaire, possibilité de chaîner les ternaires \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{structure de boucle}} \tn % Row 0 \SetRowColor{LightBackground} while~condition :\{\{nl\}\}~~~~instruction & si la condition est remplie, la boucle s'arrête \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} for~var~in~sequence :\{\{nl\}\}~~~~instruction & var prendra successivement toutes les valeurs des éléments de sequence. souvent utilisé avec range() \tn % Row Count 10 (+ 6) % Row 2 \SetRowColor{LightBackground} for ... else:\{\{nl\}\}while ... else: & la clause else est jouée si le block s'est executé sans erreur \tn % Row Count 14 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.36 cm} x{6.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{break \& continue}} \tn % Row 0 \SetRowColor{LightBackground} break & fin de boucle \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{continue} & fin d'itération (et passe à la suivante) \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import}} \tn % Row 0 \SetRowColor{LightBackground} import librairie & importe l'ensemble de la librairie \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} from librairie import methode & importe uniquement la methode utile (à combiner avec le as) \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{gestion des erreurs}} \tn % Row 0 \SetRowColor{LightBackground} try: & le code qui suit le bloc try initie potentiellement une erreur \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} except nameerror: & intercepte l'erreur pour jouer le bloc qui suit \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} finally: & dans tous les cas joué (erreur ou pas erreur) \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} else: & joué si aucune erreur levée \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} raise \seqsplit{nameerror('message')} & permet de lever une erreur pour un traitement ulterieur \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{gestion des fichiers}} \tn % Row 0 \SetRowColor{LightBackground} from pathlib import Path & permet d'écrire Path.methode() \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Path.cwd() & répertoire courant \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} Path.home() & renvoie la home \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{Path(r'/home/cptain/bin')} & crée tout de même l'objet de type fichier même si le chemin n'existe pas \tn % Row Count 8 (+ 4) % Row 4 \SetRowColor{LightBackground} Path.home() .joinpath('bin', 'bash/') & association de chemin \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{accès au fichier}} \tn % Row 0 \SetRowColor{LightBackground} with p.open() as f:\{\{nl\}\}~~~~f.methode\_Path & avec p un posixPath, cette manière de faire évite de devoir fermer le fichier après le traitement \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} f.read() & permet la lecture d'un fichier entier \tn % Row Count 7 (+ 2) % Row 2 \SetRowColor{LightBackground} f.readline() & permet de lire une ligne du fichier jusqu'au prochain \textbackslash{}n \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} f.readlines() & créer une liste composée des lignes fi fichier \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} f.write() & écrire dans un fichier \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} f.writelines() & écrire à partir d'une liste \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} f.seek(nb) & positionne le curseur au début si nb=0, à la fin si nb=2 \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} FileNotFoundError & Fichier introuvable (Erreur sur le nom du fichier ou fichier injoignable) \tn % Row Count 24 (+ 4) % Row 8 \SetRowColor{LightBackground} PermissionError & Erreur d'accès (Les droits ugo ou erreur de propriétaire) \tn % Row Count 27 (+ 3) % Row 9 \SetRowColor{white} IOError & Erreur d'ouverture \tn % Row Count 28 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{méthodes spéciales (les dunders)}} \tn % Row 0 \SetRowColor{LightBackground} \_\_repr\_\_(self) & affiche une information pour le développeur \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \_\_str\_\_(self) & fourrnit un affichage pour l'utilisateur \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{\_\_ge\_\_(self}, other) & \textgreater{}= \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{\_\_le\_\_(self}, other) & \textless{}= \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{\_\_lt\_\_(self}, other) & \textless{} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{\_\_eq\_\_(self}, other) & == \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{\_\_ne\_\_(self}, other) & != \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{\_\_add\_\_(self}, other) & + \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{\_\_mul\_\_(self}, other) & * \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{\_\_truediv\_\_(self}, other) & / \tn % Row Count 20 (+ 2) % Row 10 \SetRowColor{LightBackground} \_\_del\_\_(self) & detruire une objet del() \tn % Row Count 21 (+ 1) % Row 11 \SetRowColor{white} \_\_len\_\_(self) & Redéfinition de len() \tn % Row Count 22 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}