formations/python/python3/fr/_build/html/stdlib.html
2018-08-21 10:25:44 +02:00

346 lines
26 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>La librairie standard &#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="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>&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="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> &raquo;
</ul>
</div>
<p>&nbsp;</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">&gt;&gt;&gt; </span><span class="nb">dir</span><span class="p">(</span><span class="s1">&#39;__builtins__&#39;</span><span class="p">)</span>
<span class="go">[&#39;__add__&#39;, &#39;__class__&#39;, &#39;__contains__&#39;, &#39;__delattr__&#39;, &#39;__doc__&#39;, &#39;__eq__&#39;,</span>
<span class="go">&#39;__format__&#39;, &#39;__ge__&#39;, &#39;__getattribute__&#39;, &#39;__getitem__&#39;, &#39;__getnewargs__&#39;,</span>
<span class="go">&#39;__getslice__&#39;, &#39;__gt__&#39;, &#39;__hash__&#39;, &#39;__init__&#39;, &#39;__le__&#39;, &#39;__len__&#39;, &#39;__lt__&#39;,</span>
<span class="go">&#39;__mod__&#39;, &#39;__mul__&#39;, &#39;__ne__&#39;, &#39;__new__&#39;, &#39;__reduce__&#39;, &#39;__reduce_ex__&#39;,</span>
<span class="go">&#39;__repr__&#39;, &#39;__rmod__&#39;, &#39;__rmul__&#39;, &#39;__setattr__&#39;, &#39;__sizeof__&#39;, &#39;__str__&#39;,</span>
<span class="go">&#39;__subclasshook__&#39;, &#39;_formatter_field_name_split&#39;, &#39;_formatter_parser&#39;,</span>
<span class="go">&#39;capitalize&#39;, &#39;center&#39;, &#39;count&#39;, &#39;decode&#39;, &#39;encode&#39;, &#39;endswith&#39;, &#39;expandtabs&#39;,</span>
<span class="go">&#39;find&#39;, &#39;format&#39;, &#39;index&#39;, &#39;isalnum&#39;, &#39;isalpha&#39;, &#39;isdigit&#39;, &#39;islower&#39;,</span>
<span class="go">&#39;isspace&#39;, &#39;istitle&#39;, &#39;isupper&#39;, &#39;join&#39;, &#39;ljust&#39;, &#39;lower&#39;, &#39;lstrip&#39;,</span>
<span class="go">&#39;partition&#39;, &#39;replace&#39;, &#39;rfind&#39;, &#39;rindex&#39;, &#39;rjust&#39;, &#39;rpartition&#39;, &#39;rsplit&#39;,</span>
<span class="go">&#39;rstrip&#39;, &#39;split&#39;, &#39;splitlines&#39;, &#39;startswith&#39;, &#39;strip&#39;, &#39;swapcase&#39;, &#39;title&#39;,</span>
<span class="go">&#39;translate&#39;, &#39;upper&#39;, &#39;zfill&#39;]</span>
<span class="go">&gt;&gt;&gt;</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">&gt;&gt;&gt; </span><span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;ls&quot;</span><span class="p">,</span> <span class="s2">&quot;-l&quot;</span><span class="p">])</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">(</span><span class="s2">&quot;exit 1&quot;</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">&gt;&gt;&gt; </span><span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">([</span><span class="s2">&quot;echo&quot;</span><span class="p">,</span> <span class="s2">&quot;Hello World!&quot;</span><span class="p">])</span>
<span class="go">&#39;Hello World!\n&#39;</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">(</span><span class="s2">&quot;exit 1&quot;</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 &#39;exit 1&#39; 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 quil 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">&quot;&quot;&quot;</span>
<span class="sd">Module docstring.</span>
<span class="sd">&quot;&quot;&quot;</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">&quot;&quot;&quot;</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"> &quot;&quot;&quot;</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">&#39;-h&#39;</span><span class="p">,</span> <span class="s1">&#39;--help&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;help&#39;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s1">&#39;Show this help message and exit.&#39;</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">&#39;program takes no command-line arguments; &#39;</span>
<span class="s1">&#39;&quot;</span><span class="si">%s</span><span class="s1">&quot; ignored.&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">args</span><span class="p">,))</span>
<span class="c1"># further process settings &amp; 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">&#39;__main__&#39;</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">&quot;testFile.xml&quot;</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">&quot;Books&quot;</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">&quot;%A, %B </span><span class="si">%d</span><span class="s2">, %Y, %I:%M %p&quot;</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">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">getpass</span>
<span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">p</span>
<span class="go">&#39;toto&#39;</span>
<span class="go">&gt;&gt;&gt;</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">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">shelve</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">shelve</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;database&quot;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)</span>
<span class="go">{}</span>
<span class="gp">&gt;&gt;&gt; </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">&quot;database&quot;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span>
<span class="go">{}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="p">[</span><span class="s2">&quot;o&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </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">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span><span class="n">s</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="go">&gt;&gt;&gt;</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">&#39;toto.txt&#39;</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 &lt; 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">&#39;</span><span class="si">{0}</span><span class="s1">/</span><span class="si">{1}</span><span class="s1">&#39;</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">&quot;marche pas&quot;</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> | &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="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> &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>