formations/python/python3/fr/_build/html/getting-started.html

215 lines
10 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Prise en main &#8212; Documentation Formation Python 1</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/translations.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Recherche" href="search.html" />
<link rel="next" title="Mettre en place son environnement de travail" href="settings.html" />
<link rel="prev" title="Apprentissage de la programmation avec python" href="index.html" />
</head>
<body>
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
<table><tr><td>
<img src="_static/sphinx.png" alt="logo" />
</td><td>
<h1>&nbsp; &nbsp; Programmation python</h1>
</td></tr></table>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="Index général"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Index des modules Python"
>modules</a> |</li>
<li class="right" >
<a href="settings.html" title="Mettre en place son environnement de travail"
accesskey="N">suivant</a> |</li>
<li class="right" >
<a href="index.html" title="Apprentissage de la programmation avec python"
accesskey="P">précédent</a> |</li>
<a href="index.html">Programmation python </a> &raquo;
</ul>
</div>
<p>&nbsp;</p>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="prise-en-main">
<h1>Prise en main<a class="headerlink" href="#prise-en-main" title="Lien permanent vers ce titre"></a></h1>
<p>Lobjectif de ce cours est de vous apprendre à programmer en
<a class="reference internal" href="#term-python"><span class="xref std std-term">python</span></a>. Ce cours a été fait avec <a class="reference internal" href="#term-sphinx"><span class="xref std std-term">sphinx</span></a>, loutil de
gestion de documentation en python utilisé pour documenter python lui-même.</p>
<p>Pour plus dinformation : <a class="reference internal" href="docutils.html"><span class="doc">Sphinx et docutils</span></a></p>
<p>Avec python :</p>
<ul>
<li><p class="first">vous navez pas grand chose à savoir pour arriver à faire beaucoup de choses,</p>
</li>
<li><p class="first">vous allez pouvoir travailler de manière</p>
<ul class="simple">
<li>entièrement autonome</li>
<li>rapide</li>
<li>agile (au sens des méthodes agiles)</li>
</ul>
</li>
<li><p class="first">vous allez progresser rapidement</p>
</li>
<li><p class="first">aucune connaissance préalable en programmation nest requise</p>
</li>
<li><p class="first">le hello world en une ligne:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">c</span> <span class="s2">&quot;print &#39;hello&#39;&quot;</span>
</pre></div>
</div>
</li>
<li><p class="first">rendre un fichier exécutable et ajouter le she bang:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="nb">print</span> <span class="s2">&quot;hello&quot;</span>
</pre></div>
</div>
</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">lorsquon lance python sur un programme, des fichiers
avec une extension <code class="docutils literal"><span class="pre">.pyc</span></code> apparaissent.</p>
</div>
<dl class="glossary docutils">
<dt id="term-python">python</dt>
<dd><a class="reference external" href="http://www.python.org">python</a> est un langage de programmation généraliste, libre, totalement
orienté objet, dynamiquement typé, semi-interprété ou, pour certaines
utilisations optimisées, compilé ou compilé à la volée (JIT).</dd>
<dt id="term-sphinx">sphinx</dt>
<dd><a class="reference external" href="http://sphinx.pocoo.org">sphinx</a> est un outil de documentation utilisant la syntaxe wiki
<a class="reference external" href="http://docutils.sf.net">docutils</a></dd>
</dl>
<ul class="simple">
<li>lorsquon lance python sans spécifier de nom de fichier, cest linterpréteur
python qui est lancé (le «&nbsp;prompt&nbsp;»)</li>
</ul>
<p>En python, le dicton le plus répandu est «&nbsp;there must be an obvious way
to do it&nbsp;», (il y a certainement une manière évidente de le faire en
python), <code class="docutils literal"><span class="pre">import</span> <span class="pre">this</span></code> permet de se remémorer les
dictons de python. Ce dicton est très différent de lapproche du perl
par exemple, qui présuppose : «&nbsp;there is more than one way to do it&nbsp;»,
cest-à-dire que en gros en perl, on peut le faire nimporte comment,
mais pas en python, enfin en python cest pas conseillé de le faire à sa
sauce, il y a en général une bonne pratique à découvrir et à mettre en place.</p>
<p>Taper «&nbsp;python&nbsp;» dans votre console</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="s2">&quot;hello world&quot;</span>
<span class="go">hello world</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">this</span>
<span class="go">Beautiful is better than ugly.</span>
<span class="go">Explicit is better than implicit.</span>
<span class="go">Simple is better than complex.</span>
<span class="go">Complex is better than complicated.</span>
<span class="gp">...</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">Voir aussi</p>
<dl class="last docutils">
<dt>les modules, <a class="reference internal" href="specialmethods.html#namespaces"><span class="std std-ref">les espaces de nommage</span></a> et la librairie standard</dt>
<dd><a class="reference internal" href="stdlib.html"><span class="doc">La librairie standard</span></a></dd>
</dl>
</div>
<p>pour avoir de laide, taper dans le prompt :</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">help</span><span class="p">(</span><span class="n">function</span><span class="p">)</span>
</pre></div>
</div>
<p>Le bon réflexe de chercher ce qui est le plus répandu et le plus utilisé est le
bon en python : on dit que python est livré «&nbsp;batteries included&nbsp;», ce qui
signifie que lorsquon a un besoin précis il faut chercher dans la librairie
standard python, puis dans les librairies les plus utilisées en python, puis en
dernier… le reste, ce qui est disponible. Mais si une librairie connue ne
fait pas exactement ce qui est attendu et quune libraire inconnue du bataillon
fait exactement ce qui est attendu, (et a lair de fonctionner
correctement…), alors il faut choisir la libraire inconnue au bataillon.</p>
<div class="section" id="usage-de-python">
<h2>usage de python<a class="headerlink" href="#usage-de-python" title="Lien permanent vers ce titre"></a></h2>
<p>à peu près tous les domaines de linformatique, du scripting système à la génération
de pdf en passant par le développement web et le développement rapide dapplications.</p>
<p>exemple : web server</p>
<p>pour créer un serveur web simplement:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">server</span><span class="o">.</span><span class="n">http</span> <span class="mi">8000</span> <span class="n">localhost</span>
</pre></div>
</div>
<p>exemple : utiliser python pour faire un fichier de conf</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">spam</span> <span class="o">=</span> <span class="s2">&quot;eggs&quot;</span>
<span class="n">actions</span> <span class="o">=</span> <span class="p">[</span>
<span class="p">(</span><span class="s1">&#39;call_view&#39;</span><span class="p">,</span> <span class="s1">&#39;com.next&#39;</span><span class="p">)</span>
<span class="p">]</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
<a href="search.html"> Recherche</a> | &nbsp;
<!-- a href="genindex.html"> Genindex</a-->
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="Index général"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Index des modules Python"
>modules</a> |</li>
<li class="right" >
<a href="settings.html" title="Mettre en place son environnement de travail"
>suivant</a> |</li>
<li class="right" >
<a href="index.html" title="Apprentissage de la programmation avec python"
>précédent</a> |</li>
<a href="index.html">Programmation python </a> &raquo;
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2015, cadoles (www.cadoles.com).
Créé avec <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
</div>
</body>
</html>