\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{Theo666} \pdfinfo{ /Title (chap-8.pdf) /Creator (Cheatography) /Author (Theo666) /Subject (Chap\_8 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}{79B352} \definecolor{LightBackground}{HTML}{F6FAF4} \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{Chap\_8 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Theo666} via \textcolor{DarkBackground}{\uline{cheatography.com/193738/cs/40339/}}} \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}Theo666 \\ \uline{cheatography.com/theo666} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 25th September, 2023.\\ Updated 25th September, 2023.\\ 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*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Module}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{In Python, a module is a file containing Python definitions and statements. It can define functions, classes, and variables, and can also include runnable code. Grouping related code into a module makes the code easier to understand and use, and it also makes the code logically organized.% Row Count 6 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Common Modules}} \tn % Row 0 \SetRowColor{LightBackground} math & fonctions et constantes mathématiques de base \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} sys & interaction avec l'interpréteur Python, passage d'arguments \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} os & dialogue avec le système d'exploitation \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} random & génération de nombres aléatoires \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} time & accès à l'heure de l'ordinateur et aux fonctions gérant le temps. \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} urlib & récupération de données sur internet depuis Python \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} Tkinter & interface python avec Tk. Création d'objets graphiques \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} re & gestion des expressions régulières \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} Numpy & manipulations de vecteurs et de matrices, algèbre linéaire \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{Biopython} & recherche dans les banques de données biologiques, manipulation de séquences ou de structures de biomolécules \tn % Row Count 23 (+ 4) % Row 10 \SetRowColor{LightBackground} \seqsplit{matplotlib} & eprésentations graphiques : courbes, nuages de points, diagrammes en bâtons... \tn % Row Count 26 (+ 3) % Row 11 \SetRowColor{white} pandas & analyse de données \tn % Row Count 27 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Load \& usage}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\# Method 1 \newline import module \newline import module as xx \newline module.function() \newline \newline \# Method 2 \newline from module import function \newline from module import function1, function2 \newline function() \newline \newline \# Method 3 \newline from module import * \newline function() \newline \newline \# to unload a module \newline del module \newline \newline \# to get help \newline help(module) \newline / text \# to find the key word \newline Q \# exit} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{To avoid confusion between functions or constants with the same name from different modules, it is advisable to load the module by calling its name while using a function or a constant (Method 1) specially for the module math} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{module Random}} \tn % Row 0 \SetRowColor{LightBackground} random.random() & a random float uniformly in the half-open range 0.0 \textless{}= X \textless{} 1.01 \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} random.randint(a,b) & It returns a random integer from the specified range {[}a, b{]}, inclusive \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} random.choice(seq) & returns a random element from the non-empty sequence seq \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} random.shuffle(x) & randomly shuffles the elements of the list x in place \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{random.randrange(start}, stop, step) & returns a randomly selected element from the specified range \tn % Row Count 18 (+ 4) % Row 5 \SetRowColor{white} random.choices(seq, weight = c() , k =) & It returns a list with the randomly selected element from the specified sequence \tn % Row Count 22 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{choice(seq) \& choices (seq, weight, k) The sequence can be a string, a range, a list, a tuple, or any other kind of sequence} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{common functions}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- Le module {\bf{sys}} pour récupérer les arguments passés à un script Python. {\bf{python file.py xx xx}} dans un shell {\bf{sys.argv}} dans le py fircher renvoie une liste des arguments y compris le nom du script lui-même sys.argv{[}0{]}. accéder aux arguments avec {\bf{sys.argv{[}1{]}, sys.argv{[}2{]}}} \newline % Row Count 6 (+ 6) - Le module {\bf{os}} gère l'interface avec le système d'exploitation. \newline % Row Count 8 (+ 2) La fonction {\bf{os.path.exists()}} vérifie la présence d'un fichier sur le disque dur. Il renvoie True ou False \newline % Row Count 11 (+ 3) La fonction {\bf{sys.exit("message")}} est pour quitter le programme. Il est possible de renvoyer une message dans le shell \newline % Row Count 14 (+ 3) La fonction {\bf{os.getcwd()}} renvoie le répertoire (sous forme de chemin complet) depuis le directoire du travail \newline % Row Count 17 (+ 3) {\bf{os.getdir()}} same to ls in Linux and dir() in R \newline % Row Count 19 (+ 2) - time.sleep() \newline % Row Count 20 (+ 1) - math.sqrt()% Row Count 21 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}