Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-updates > by-pkgid > b9a6a1b9f2781444d2917afd8e4421ab > files > 885

ipython-doc-2.3.0-2.2.mga5.noarch.rpm

<!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">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Module: utils.contexts &mdash; IPython 2.3.0 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '2.3.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </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>
    <link rel="top" title="IPython 2.3.0 documentation" href="../../index.html" />
    <link rel="up" title="The IPython API" href="../index.html" />
    <link rel="next" title="Module: utils.daemonize" href="IPython.utils.daemonize.html" />
    <link rel="prev" title="Module: utils.coloransi" href="IPython.utils.coloransi.html" /> 
  </head>
  <body>

<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
<a href="http://ipython.org/"><img src="../../_static/logo.png" border="0" alt="IPython Documentation"/></a>
</div>

    <div class="related">
      <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="IPython.utils.daemonize.html" title="Module: utils.daemonize"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="IPython.utils.coloransi.html" title="Module: utils.coloransi"
             accesskey="P">previous</a> |</li>
        <li><a href="http://ipython.org">home</a>|&nbsp;</li>
        <li><a href="../../search.html">search</a>|&nbsp;</li>
       <li><a href="../../index.html">documentation </a> &raquo;</li>

          <li><a href="../index.html" accesskey="U">The IPython API</a> &raquo;</li> 
      </ul>
    </div>

      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Module: <tt class="docutils literal"><span class="pre">utils.contexts</span></tt></a><ul>
<li><a class="reference internal" href="#class">1 Class</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="IPython.utils.coloransi.html"
                        title="previous chapter">Module: <tt class="docutils literal"><span class="pre">utils.coloransi</span></tt></a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="IPython.utils.daemonize.html"
                        title="next chapter">Module: <tt class="docutils literal"><span class="pre">utils.daemonize</span></tt></a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../_sources/api/generated/IPython.utils.contexts.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-IPython.utils.contexts">
<span id="module-utils-contexts"></span><h1>Module: <tt class="xref py py-mod docutils literal"><span class="pre">utils.contexts</span></tt><a class="headerlink" href="#module-IPython.utils.contexts" title="Permalink to this headline">¶</a></h1>
<p>Context managers for temporarily updating dictionaries.</p>
<p>Authors:</p>
<ul class="simple">
<li>Bradley Froehle</li>
</ul>
<div class="section" id="class">
<h2>1 Class<a class="headerlink" href="#class" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="IPython.utils.contexts.preserve_keys">
<em class="property">class </em><tt class="descclassname">IPython.utils.contexts.</tt><tt class="descname">preserve_keys</tt><big>(</big><em>dictionary</em>, <em>*keys</em><big>)</big><a class="headerlink" href="#IPython.utils.contexts.preserve_keys" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="http://docs.python.org/2/library/functions.html#object" title="(in Python v2.7)"><tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></a></p>
<p>Preserve a set of keys in a dictionary.</p>
<p>Upon entering the context manager the current values of the keys
will be saved. Upon exiting, the dictionary will be updated to
restore the original value of the preserved keys. Preserved keys
which did not exist when entering the context manager will be
deleted.</p>
<p class="rubric">Examples</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;a&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s">&#39;c&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">preserve_keys</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">,</span> <span class="s">&#39;c&#39;</span><span class="p">,</span> <span class="s">&#39;d&#39;</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">del</span> <span class="n">d</span><span class="p">[</span><span class="s">&#39;a&#39;</span><span class="p">]</span>
<span class="gp">... </span>    <span class="k">del</span> <span class="n">d</span><span class="p">[</span><span class="s">&#39;b&#39;</span><span class="p">]</span>      <span class="c"># will be reset to 2</span>
<span class="gp">... </span>    <span class="n">d</span><span class="p">[</span><span class="s">&#39;c&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">None</span>   <span class="c"># will be reset to 3</span>
<span class="gp">... </span>    <span class="n">d</span><span class="p">[</span><span class="s">&#39;d&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">4</span>      <span class="c"># will be deleted</span>
<span class="gp">... </span>    <span class="n">d</span><span class="p">[</span><span class="s">&#39;e&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">... </span>    <span class="k">print</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()))</span>
<span class="gp">...</span>
<span class="go">[(&#39;c&#39;, None), (&#39;d&#39;, 4), (&#39;e&#39;, 5)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">items</span><span class="p">()))</span>
<span class="go">[(&#39;b&#39;, 2), (&#39;c&#39;, 3), (&#39;e&#39;, 5)]</span>
</pre></div>
</div>
<dl class="method">
<dt id="IPython.utils.contexts.preserve_keys.__init__">
<tt class="descname">__init__</tt><big>(</big><em>dictionary</em>, <em>*keys</em><big>)</big><a class="headerlink" href="#IPython.utils.contexts.preserve_keys.__init__" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <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="IPython.utils.daemonize.html" title="Module: utils.daemonize"
             >next</a> |</li>
        <li class="right" >
          <a href="IPython.utils.coloransi.html" title="Module: utils.coloransi"
             >previous</a> |</li>
        <li><a href="http://ipython.org">home</a>|&nbsp;</li>
        <li><a href="../../search.html">search</a>|&nbsp;</li>
       <li><a href="../../index.html">documentation </a> &raquo;</li>

          <li><a href="../index.html" >The IPython API</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright The IPython Development Team.
      Last updated on Jul 14, 2015.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
    </div>
  </body>
</html>