346 lines
26 KiB
HTML
346 lines
26 KiB
HTML
|
|
|||
|
<!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>La librairie standard — 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="Liste des exercices" href="exercices.html" />
|
|||
|
<link rel="prev" title="Les design patterns" href="DesignPatterns.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> 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="exercices.html" title="Liste des exercices"
|
|||
|
accesskey="N">suivant</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="DesignPatterns.html" title="Les design patterns"
|
|||
|
accesskey="P">précédent</a> |</li>
|
|||
|
<a href="index.html">Programmation python </a> »
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
|
|||
|
<div class="document">
|
|||
|
<div class="documentwrapper">
|
|||
|
<div class="bodywrapper">
|
|||
|
<div class="body" role="main">
|
|||
|
|
|||
|
<div class="section" id="la-librairie-standard">
|
|||
|
<h1>La <a class="reference internal" href="settings.html#term-librairie-standard"><span class="xref std std-term">librairie standard</span></a><a class="headerlink" href="#la-librairie-standard" title="Lien permanent vers ce titre">¶</a></h1>
|
|||
|
<div class="section" id="module-builtins">
|
|||
|
<span id="les-builtins"></span><h2>les builtins<a class="headerlink" href="#module-builtins" title="Lien permanent vers ce titre">¶</a></h2>
|
|||
|
<ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-builtins" title="builtins: les fonctions directement à disposition sans import spécifique"><code class="xref py py-mod docutils literal"><span class="pre">builtins</span></code></a>, tout ce qui est accessible directement</li>
|
|||
|
</ul>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">dir</span><span class="p">(</span><span class="s1">'__builtins__'</span><span class="p">)</span>
|
|||
|
<span class="go">['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__',</span>
|
|||
|
<span class="go">'__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__',</span>
|
|||
|
<span class="go">'__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__',</span>
|
|||
|
<span class="go">'__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',</span>
|
|||
|
<span class="go">'__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__',</span>
|
|||
|
<span class="go">'__subclasshook__', '_formatter_field_name_split', '_formatter_parser',</span>
|
|||
|
<span class="go">'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs',</span>
|
|||
|
<span class="go">'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower',</span>
|
|||
|
<span class="go">'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip',</span>
|
|||
|
<span class="go">'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit',</span>
|
|||
|
<span class="go">'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title',</span>
|
|||
|
<span class="go">'translate', 'upper', 'zfill']</span>
|
|||
|
<span class="go">>>></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-subprocess" title="subprocess: exécuter une commande shell, récupérer le code retour et la sortie"><code class="xref py py-mod docutils literal"><span class="pre">subprocess</span></code></a>, appels systèmes</li>
|
|||
|
</ul>
|
|||
|
<span class="target" id="module-subprocess"></span><dl class="function">
|
|||
|
<dt>
|
|||
|
<code class="descname">subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)¶</code></dt>
|
|||
|
<dd></dd></dl>
|
|||
|
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">"ls"</span><span class="p">,</span> <span class="s2">"-l"</span><span class="p">])</span>
|
|||
|
<span class="go">0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">(</span><span class="s2">"exit 1"</span><span class="p">,</span> <span class="n">shell</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|||
|
<span class="go">1</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<dl class="function">
|
|||
|
<dt>
|
|||
|
<code class="descname">subprocess.check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)¶</code></dt>
|
|||
|
<dd></dd></dl>
|
|||
|
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">([</span><span class="s2">"echo"</span><span class="p">,</span> <span class="s2">"Hello World!"</span><span class="p">])</span>
|
|||
|
<span class="go">'Hello World!\n'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">(</span><span class="s2">"exit 1"</span><span class="p">,</span> <span class="n">shell</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|||
|
<span class="gt">Traceback (most recent call last):</span>
|
|||
|
<span class="c">...</span>
|
|||
|
<span class="gr">subprocess.CalledProcessError</span>: <span class="n">Command 'exit 1' returned non-zero exit status 1</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-sys" title="sys: paramètres et fonctions systèmes"><code class="xref py py-mod docutils literal"><span class="pre">sys</span></code></a>, paramètres et fonctions systèmes</li>
|
|||
|
</ul>
|
|||
|
<span class="target" id="module-sys"></span><dl class="envvar">
|
|||
|
<dt id="envvar-sys.argv">
|
|||
|
<code class="descname">sys.argv</code><a class="headerlink" href="#envvar-sys.argv" title="Lien permanent vers cette définition">¶</a></dt>
|
|||
|
<dd><p>la ligne de commande</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="function">
|
|||
|
<dt id="sys.sys.exit">
|
|||
|
<code class="descclassname">sys.</code><code class="descname">exit</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sys.sys.exit" title="Lien permanent vers cette définition">¶</a></dt>
|
|||
|
<dd><p>terminer un programme</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="envvar">
|
|||
|
<dt id="envvar-sys.path">
|
|||
|
<code class="descname">sys.path</code><a class="headerlink" href="#envvar-sys.path" title="Lien permanent vers cette définition">¶</a></dt>
|
|||
|
<dd><p>ce qu’il y a dans le <span class="target" id="index-0"></span><a class="reference internal" href="settings.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONPATH</span></code></a></p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<span class="target" id="module-optparse"></span><ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-optparse" title="optparse: parsing de la ligne de commande"><code class="xref py py-mod docutils literal"><span class="pre">optparse</span></code></a> pour faire des outils ligne de commande</li>
|
|||
|
</ul>
|
|||
|
<p>module plus récent : argparse</p>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|||
|
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd">Module docstring.</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
|
|||
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|||
|
<span class="kn">import</span> <span class="nn">optparse</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">process_command_line</span><span class="p">(</span><span class="n">argv</span><span class="p">):</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd"> Return a 2-tuple: (settings object, args list).</span>
|
|||
|
<span class="sd"> `argv` is a list of arguments, or `None` for ``sys.argv[1:]``.</span>
|
|||
|
<span class="sd"> """</span>
|
|||
|
<span class="k">if</span> <span class="n">argv</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|||
|
<span class="n">argv</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
|
|||
|
|
|||
|
<span class="c1"># initialize the parser object:</span>
|
|||
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">(</span>
|
|||
|
<span class="n">formatter</span><span class="o">=</span><span class="n">optparse</span><span class="o">.</span><span class="n">TitledHelpFormatter</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="mi">78</span><span class="p">),</span>
|
|||
|
<span class="n">add_help_option</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="c1"># define options here:</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span> <span class="c1"># customized description; put --help last</span>
|
|||
|
<span class="s1">'-h'</span><span class="p">,</span> <span class="s1">'--help'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'help'</span><span class="p">,</span>
|
|||
|
<span class="n">help</span><span class="o">=</span><span class="s1">'Show this help message and exit.'</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="n">settings</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">(</span><span class="n">argv</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="c1"># check number of arguments, verify values, etc.:</span>
|
|||
|
<span class="k">if</span> <span class="n">args</span><span class="p">:</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">'program takes no command-line arguments; '</span>
|
|||
|
<span class="s1">'"</span><span class="si">%s</span><span class="s1">" ignored.'</span> <span class="o">%</span> <span class="p">(</span><span class="n">args</span><span class="p">,))</span>
|
|||
|
|
|||
|
<span class="c1"># further process settings & args if necessary</span>
|
|||
|
|
|||
|
<span class="k">return</span> <span class="n">settings</span><span class="p">,</span> <span class="n">args</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">argv</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
|
|||
|
<span class="n">settings</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">process_command_line</span><span class="p">(</span><span class="n">argv</span><span class="p">)</span>
|
|||
|
<span class="c1"># application code here, like:</span>
|
|||
|
<span class="c1"># run(settings, args)</span>
|
|||
|
<span class="k">return</span> <span class="mi">0</span> <span class="c1"># success</span>
|
|||
|
|
|||
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
|
|||
|
<span class="n">status</span> <span class="o">=</span> <span class="n">main</span><span class="p">()</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">status</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<ul class="simple">
|
|||
|
<li>les modules de tests unitaires <a class="reference internal" href="#module-unittest" title="unittest: module de tests unitaires"><code class="xref py py-mod docutils literal"><span class="pre">unittest</span></code></a> et <code class="xref py py-mod docutils literal"><span class="pre">doctests</span></code></li>
|
|||
|
</ul>
|
|||
|
<span class="target" id="module-unittest"></span><span class="target" id="module-doctest"></span><ul class="simple">
|
|||
|
<li>le module <code class="xref py py-mod docutils literal"><span class="pre">xml.etree</span></code> pour parser du xml</li>
|
|||
|
</ul>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">tree</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s2">"testFile.xml"</span><span class="p">)</span>
|
|||
|
<span class="n">rootElement</span> <span class="o">=</span> <span class="n">tree</span><span class="o">.</span><span class="n">getroot</span><span class="p">()</span>
|
|||
|
<span class="n">bookList</span> <span class="o">=</span> <span class="n">rootElem</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="s2">"Books"</span><span class="p">)</span>
|
|||
|
<span class="k">if</span> <span class="n">bookList</span> <span class="o">!=</span> <span class="kc">None</span><span class="p">:</span>
|
|||
|
<span class="k">for</span> <span class="n">book</span> <span class="ow">in</span> <span class="n">bookList</span><span class="p">:</span>
|
|||
|
<span class="c1">#faire quelque chose avec les livres</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-urllib" title="urllib: parse des urls"><code class="xref py py-mod docutils literal"><span class="pre">urllib</span></code></a> pour parser les urls et les manipuler (<cite>urllib2</cite>)</li>
|
|||
|
</ul>
|
|||
|
<span class="target" id="module-urllib"></span><dl class="function">
|
|||
|
<dt id="urllib.urllib.urlopen">
|
|||
|
<code class="descclassname">urllib.</code><code class="descname">urlopen</code><span class="sig-paren">(</span><em>url</em><span class="sig-paren">)</span><a class="headerlink" href="#urllib.urllib.urlopen" title="Lien permanent vers cette définition">¶</a></dt>
|
|||
|
<dd><p>lit une url distante</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<span class="target" id="module-time"></span><ul class="simple">
|
|||
|
<li><a class="reference internal" href="#module-time" title="time: caculs de temps"><code class="xref py py-mod docutils literal"><span class="pre">time</span></code></a> pour la manipulation de temps</li>
|
|||
|
</ul>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">t1</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">clock</span><span class="p">()</span>
|
|||
|
<span class="c1"># Do Stuff Here</span>
|
|||
|
<span class="n">t2</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">clock</span><span class="p">()</span>
|
|||
|
<span class="nb">print</span> <span class="n">t2</span> <span class="o">-</span> <span class="n">t1</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p><strong>now</strong></p>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span>
|
|||
|
<span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">localtime</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
|
|||
|
<span class="n">dateStr</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">"%A, %B </span><span class="si">%d</span><span class="s2">, %Y, %I:%M %p"</span><span class="p">,</span> <span class="n">now</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span> <span class="n">dateStr</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<span class="target" id="module-getpass"></span><ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-getpass" title="getpass: recupération des mots de passe en ligne de commande"><code class="xref py py-mod docutils literal"><span class="pre">getpass</span></code></a> pour gérer les motes de passe</li>
|
|||
|
</ul>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">getpass</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">getpass</span><span class="o">.</span><span class="n">getpass</span><span class="p">()</span>
|
|||
|
<span class="go">Password:</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p</span>
|
|||
|
<span class="go">'toto'</span>
|
|||
|
<span class="go">>>></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<span class="target" id="module-shelve"></span><ul class="simple">
|
|||
|
<li>linéarisation de données</li>
|
|||
|
</ul>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">shelve</span>
|
|||
|
<span class="gp">>>> </span><span class="n">shelve</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"database"</span><span class="p">,</span> <span class="s1">'c'</span><span class="p">)</span>
|
|||
|
<span class="go">{}</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">shelve</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"database"</span><span class="p">,</span> <span class="s1">'c'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span>
|
|||
|
<span class="go">{}</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span><span class="p">[</span><span class="s2">"o"</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'a'</span><span class="p">,</span> <span class="s1">'b'</span><span class="p">,</span> <span class="s1">'c'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">cl</span>
|
|||
|
<span class="go">s.clear s.close</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">cl</span>
|
|||
|
<span class="go">s.clear s.close</span>
|
|||
|
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
|||
|
<span class="go">>>></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<span class="target" id="module-abc"></span><ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-abc" title="abc: les abstract base classes"><code class="xref py py-mod docutils literal"><span class="pre">abc</span></code></a> pour faire des interfaces propres</li>
|
|||
|
</ul>
|
|||
|
<dl class="function">
|
|||
|
<dt id="abc.abc.register">
|
|||
|
<code class="descclassname">abc.</code><code class="descname">register</code><span class="sig-paren">(</span><em>subclass</em><span class="sig-paren">)</span><a class="headerlink" href="#abc.abc.register" title="Lien permanent vers cette définition">¶</a></dt>
|
|||
|
<dd><p>exemple</p>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">abc</span> <span class="k">import</span> <span class="n">ABCMeta</span>
|
|||
|
|
|||
|
<span class="k">class</span> <span class="nc">MyABC</span><span class="p">:</span>
|
|||
|
<span class="n">__metaclass__</span> <span class="o">=</span> <span class="n">ABCMeta</span>
|
|||
|
|
|||
|
<span class="n">MyABC</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="nb">tuple</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">assert</span> <span class="nb">issubclass</span><span class="p">(</span><span class="nb">tuple</span><span class="p">,</span> <span class="n">MyABC</span><span class="p">)</span>
|
|||
|
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">((),</span> <span class="n">MyABC</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<span class="target" id="module-hotshot"></span><ul class="simple">
|
|||
|
<li>le module <a class="reference internal" href="#module-hotshot" title="hotshot: benchmark"><code class="xref py py-mod docutils literal"><span class="pre">hotshot</span></code></a> benchmark</li>
|
|||
|
</ul>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">hotshot</span>
|
|||
|
<span class="n">prof</span> <span class="o">=</span> <span class="n">hotshot</span><span class="o">.</span><span class="n">Profile</span><span class="p">(</span><span class="s1">'toto.txt'</span><span class="p">)</span>
|
|||
|
<span class="n">prof</span><span class="o">.</span><span class="n">runcall</span><span class="p">(</span><span class="n">make_description</span><span class="p">)</span>
|
|||
|
<span class="n">prof</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<ul class="simple">
|
|||
|
<li>un exemple de librairie externe : <a class="reference internal" href="#module-IPy" title="IPy: traitement des ips en python < python 3.3 remplacé par ipadress"><code class="xref py py-mod docutils literal"><span class="pre">IPy</span></code></a></li>
|
|||
|
</ul>
|
|||
|
<span class="target" id="module-IPy"></span><div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sudo</span> <span class="n">apt</span><span class="o">-</span><span class="n">get</span> <span class="n">install</span> <span class="n">python</span><span class="o">-</span><span class="n">ipy</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">IPy</span> <span class="k">import</span> <span class="n">IP</span>
|
|||
|
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="n">ipy</span> <span class="o">=</span> <span class="n">IP</span><span class="p">(</span><span class="s1">'</span><span class="si">{0}</span><span class="s1">/</span><span class="si">{1}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ip</span><span class="p">,</span> <span class="n">mask</span><span class="p">),</span> <span class="n">make_net</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|||
|
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span> <span class="s2">"marche pas"</span>
|
|||
|
<span class="n">network</span> <span class="o">=</span> <span class="n">ipy</span><span class="o">.</span><span class="n">net</span><span class="p">()</span>
|
|||
|
<span class="n">broadcast</span> <span class="o">=</span> <span class="n">ipy</span><span class="o">.</span><span class="n">broadcast</span><span class="p">()</span>
|
|||
|
<span class="k">return</span> <span class="n">broadcast</span><span class="p">,</span> <span class="n">network</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> |
|
|||
|
<!-- 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="exercices.html" title="Liste des exercices"
|
|||
|
>suivant</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="DesignPatterns.html" title="Les design patterns"
|
|||
|
>précédent</a> |</li>
|
|||
|
<a href="index.html">Programmation python </a> »
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="footer" role="contentinfo">
|
|||
|
© Copyright 2015, cadoles (www.cadoles.com).
|
|||
|
Créé avec <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
|
|||
|
</div>
|
|||
|
</body>
|
|||
|
</html>
|