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

197 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>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Getting started &#8212; pyfundoc documentation</title>
<link rel="stylesheet" href="_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: ' ',
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/bizstyle.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Base types" href="base-type.html" />
<link rel="prev" title="The tasting of python" href="index.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!--[if lt IE 9]>
<script type="text/javascript" src="_static/css3-mediaqueries.js"></script>
<![endif]-->
</head>
<body>
<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="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="base-type.html" title="Base types"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="The tasting of python"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">pyfundoc documentation</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="body" role="main">
<div class="section" id="getting-started">
<h1>Getting started<a class="headerlink" href="#getting-started" title="Permalink to this headline"></a></h1>
<div class="section" id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h2>
<p>Have a look at the <a class="reference external" href="http://www.python.org">python</a> website.</p>
</div>
<div class="section" id="hello-world">
<h2>Hello world<a class="headerlink" href="#hello-world" title="Permalink to this headline"></a></h2>
<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>
<p>Opening a python prompt:</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="p">(</span><span class="s2">&quot;hello world&quot;</span><span class="p">)</span>
<span class="go">hello world</span>
</pre></div>
</div>
<div class="literal-block-wrapper docutils container" id="hello-py">
<div class="code-block-caption"><span class="caption-text">hello.py</span><a class="headerlink" href="#hello-py" title="Permalink to this code"></a></div>
<div class="highlight-python"><div class="highlight"><pre><span></span> <span class="kn">import</span> <span class="nn">sys</span>
<span class="n">name</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="k">print</span><span class="p">(</span><span class="s2">&quot;Hello, {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
</pre></div>
</div>
</div>
<p>starting a web server:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">http</span><span class="o">.</span><span class="n">server</span> <span class="mi">8080</span>
</pre></div>
</div>
<p>importing a module</p>
<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>
</pre></div>
</div>
<p>use the builtin help</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>
</div>
<div class="section" id="configure-your-prompt">
<h2>Configure your prompt<a class="headerlink" href="#configure-your-prompt" title="Permalink to this headline"></a></h2>
<p>Set your path or install a good prompt like <a class="reference external" href="https://ipython.org/ipython-doc/2/install/install.html">ipython</a></p>
<dl class="envvar">
<dt id="envvar-PYTHONPATH">
<code class="descname">PYTHONPATH</code><a class="headerlink" href="#envvar-PYTHONPATH" title="Permalink to this definition"></a></dt>
<dd><p>defaults on the current directory
you can add a path to point to some other library</p>
</dd></dl>
<p>put this in your <cite>.bashrc</cite> (under linux), under windows… I dont know:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>export PYTHONPATH:`pwd`
export PYTHONPATH=$PYTHONPATH:&#39;/usr/share&#39;:&#39;/toto/titi/tata&#39;
alias pyenv=&#39;export PYTHONPATH=`pwd`:$PYTHONPATH&#39;
export PYTHONSTARTUP=&#39;/home/gwen/.pystartup&#39;
</pre></div>
</div>
<dl class="envvar">
<dt id="envvar-PYTHONSTARTUP">
<code class="descname">PYTHONSTARTUP</code><a class="headerlink" href="#envvar-PYTHONSTARTUP" title="Permalink to this definition"></a></dt>
<dd><p>the pystartup enables us to set the</p>
<ul class="simple">
<li>autocompletion</li>
<li>the history of the commands</li>
</ul>
</dd></dl>
<p>example of <cite>.pystartup</cite></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># Store the file in ~/.pystartup, and set an environment variable to point to</span>
<span class="c1"># it, e.g. &quot;export PYTHONSTARTUP=/max/home/itamar/.pystartup&quot; in bash.</span>
<span class="c1">#</span>
<span class="c1"># Note that PYTHONSTARTUP does *not* expand &quot;~&quot;, so you have to put in the full</span>
<span class="c1"># path to your home directory.</span>
<span class="kn">import</span> <span class="nn">rlcompleter</span>
<span class="kn">import</span> <span class="nn">readline</span>
<span class="n">readline</span><span class="o">.</span><span class="n">parse_and_bind</span><span class="p">(</span><span class="s2">&quot;tab: complete&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="n">histfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;HOME&quot;</span><span class="p">],</span> <span class="s2">&quot;.pyhist&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">readline</span><span class="o">.</span><span class="n">read_history_file</span><span class="p">(</span><span class="n">histfile</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
<span class="k">pass</span>
<span class="kn">import</span> <span class="nn">atexit</span>
<span class="n">atexit</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">readline</span><span class="o">.</span><span class="n">write_history_file</span><span class="p">,</span> <span class="n">histfile</span><span class="p">)</span>
<span class="k">del</span> <span class="n">os</span><span class="p">,</span> <span class="n">histfile</span>
<span class="c1"># enhanced completion</span>
<span class="c1">#import rlcompleter2</span>
<span class="c1">#rlcompleter2.setup()</span>
</pre></div>
</div>
</div>
<div class="section" id="editors">
<h2>Editors<a class="headerlink" href="#editors" title="Permalink to this headline"></a></h2>
<p>IDLE</p>
<p><a class="reference external" href="https://docs.python.org/3/library/idle.html">https://docs.python.org/3/library/idle.html</a></p>
<p>un framework de développement intégré : <a class="reference internal" href="#term-idle"><span class="xref std std-term">IDLE</span></a></p>
<dl class="glossary docutils">
<dt id="term-idle">IDLE</dt>
<dd><a class="reference external" href="http://docs.python.org/3/library/idle.html">IDLE</a> is an IDE (Integrated Development Environnement)</dd>
</dl>
<p><a class="reference external" href="https://thonny.org/">Thonny</a></p>
<p>Otherwise, your preferred editor…</p>
</div>
</div>
</div>
</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="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="base-type.html" title="Base types"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="The tasting of python"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">pyfundoc documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
</div>
</body>
</html>