Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 82fd441cd3f2a8bc33fc3ed41403eced > files > 1410

python-astropy-0.2.4-4.mga4.x86_64.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>find_current_module &mdash; Astropy v0.2.4</title>
    
    <link rel="stylesheet" href="../_static/bootstrap-astropy.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.2.4',
        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>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="shortcut icon" href="../_static/astropy_logo.ico"/>
    <link rel="top" title="Astropy v0.2.4" href="../index.html" />
    <link rel="up" title="Astropy Core Package Utilities (astropy.utils)" href="../utils/index.html" />
    <link rel="next" title="isiterable" href="astropy.utils.misc.isiterable.html" />
    <link rel="prev" title="XMLWriter" href="astropy.utils.xml.writer.XMLWriter.html" /> 
  </head>
  <body>
<div class="topbar">
  <a class="brand" title="Documentation Home" href="../index.html"></a>
  <ul>
    <li><a class="homelink" title="AstroPy Homepage" href="http://www.astropy.org"></a></li>
    <li><a title="General Index" href="../genindex.html">Index</a></li>
    <li><a title="Python Module Index" href="../py-modindex.html">Modules</a></li>
    <li>
      
      
<form action="../search.html" method="get">
  <input type="text" name="q" placeholder="Search" />
  <input type="hidden" name="check_keywords" value="yes" />
  <input type="hidden" name="area" value="default" />
</form>
      
    </li>
  </ul>
</div>

<div class="related">
    <h3>Navigation</h3>
    <ul>
      <li class="right">
	<a href="astropy.utils.misc.isiterable.html" title="isiterable">
	  next &raquo;
	</a>
      </li>
      <li class="right">
	<a href="astropy.utils.xml.writer.XMLWriter.html" title="XMLWriter">
	  &laquo; previous
	</a>
	 |
      </li>
      <li>
	<a href="../index.html">Astropy v0.2.4</a>
	 &raquo;
      </li>
      <li><a href="../utils/index.html" accesskey="U">Astropy Core Package Utilities (<tt class="docutils literal"><span class="pre">astropy.utils</span></tt>)</a> &raquo;</li>
      
      <li>find_current_module</li> 
    </ul>
</div>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="find-current-module">
<h1>find_current_module<a class="headerlink" href="#find-current-module" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="astropy.utils.misc.find_current_module">
<tt class="descclassname">astropy.utils.misc.</tt><tt class="descname">find_current_module</tt><big>(</big><em>depth=1</em>, <em>finddiff=False</em><big>)</big><a class="reference external" href="http://github.com/astropy/astropy/tree/v0.2.4/astropy/utils/misc.py#L24" title="Push the Edit button on the next page"><span class="edit-on-github viewcode-link">&nbsp;[edit on github]</span></a><a class="reference internal" href="../_modules/astropy/utils/misc.html#find_current_module"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#astropy.utils.misc.find_current_module" title="Permalink to this definition">¶</a></dt>
<dd><p>Determines the module/package from which this function is called.</p>
<p>This function has two modes, determined by the <tt class="xref py py-obj docutils literal"><span class="pre">finddiff</span></tt> option. it
will either simply go the requested number of frames up the call
stack (if <tt class="xref py py-obj docutils literal"><span class="pre">finddiff</span></tt> is False), or it will go up the call stack until
it reaches a module that is <em>not</em> in a specified set.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters :</th><td class="field-body"><p class="first"><strong>depth</strong> : int</p>
<blockquote>
<div><p>Specifies how far back to go in the call stack (0-indexed, so that
passing in 0 gives back <a class="reference internal" href="../utils/index.html#module-astropy.utils.misc" title="astropy.utils.misc"><tt class="xref py py-obj docutils literal"><span class="pre">astropy.utils.misc</span></tt></a>).</p>
</div></blockquote>
<p><strong>finddiff</strong> : bool or list</p>
<blockquote>
<div><p>If False, the returned <tt class="xref py py-obj docutils literal"><span class="pre">mod</span></tt> will just be <tt class="xref py py-obj docutils literal"><span class="pre">depth</span></tt> frames up from
the current frame. Otherwise, the function will start at a frame
<tt class="xref py py-obj docutils literal"><span class="pre">depth</span></tt> up from current, and continue up the call stack to the
first module that is <em>different</em> from those in the provided list.
In this case, <tt class="xref py py-obj docutils literal"><span class="pre">finddiff</span></tt> can be a list of modules or modules
names. Alternatively, it can be True, which will use the module
<tt class="xref py py-obj docutils literal"><span class="pre">depth</span></tt> call stack frames up as the module the returned module
most be different from.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns :</th><td class="field-body"><p class="first"><strong>mod</strong> : module or None</p>
<blockquote>
<div><p>The module object or None if the package cannot be found. The name of
the module is available as the <tt class="docutils literal"><span class="pre">__name__</span></tt> attribute of the returned
object (if it isn&#8217;t None).</p>
</div></blockquote>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises :</th><td class="field-body"><p class="first"><strong>ValueError</strong> :</p>
<blockquote class="last">
<div><p>If <tt class="xref py py-obj docutils literal"><span class="pre">finddiff</span></tt> is a list with an invalid entry.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Examples</p>
<p>The examples below assume that there are two modules in a package named
<tt class="xref py py-obj docutils literal"><span class="pre">pkg</span></tt>. <tt class="docutils literal"><span class="pre">mod1.py</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">find1</span><span class="p">():</span>
    <span class="kn">from</span> <span class="nn">astropy.utils</span> <span class="kn">import</span> <span class="n">find_current_module</span>
    <span class="k">print</span> <span class="n">find_current_module</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">__name__</span>
<span class="k">def</span> <span class="nf">find2</span><span class="p">():</span>
    <span class="kn">from</span> <span class="nn">astropy.utils</span> <span class="kn">import</span> <span class="n">find_current_module</span>
    <span class="n">cmod</span> <span class="o">=</span> <span class="n">find_current_module</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">cmod</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="k">print</span> <span class="s">&#39;None&#39;</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">print</span> <span class="n">cmod</span><span class="o">.</span><span class="n">__name__</span>
<span class="k">def</span> <span class="nf">find_diff</span><span class="p">():</span>
    <span class="kn">from</span> <span class="nn">astropy.utils</span> <span class="kn">import</span> <span class="n">find_current_module</span>
    <span class="k">print</span> <span class="n">find_current_module</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">True</span><span class="p">)</span><span class="o">.</span><span class="n">__name__</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">mod2.py</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">find</span><span class="p">():</span>
    <span class="kn">from</span> <span class="nn">.mod1</span> <span class="kn">import</span> <span class="n">find2</span>
    <span class="n">find2</span><span class="p">()</span>
</pre></div>
</div>
<p>With these modules in place, the following occurs:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pkg</span> <span class="kn">import</span> <span class="n">mod1</span><span class="p">,</span> <span class="n">mod2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">astropy.utils</span> <span class="kn">import</span> <span class="n">find_current_module</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mod1</span><span class="o">.</span><span class="n">find1</span><span class="p">()</span>
<span class="go">pkg.mod1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mod1</span><span class="o">.</span><span class="n">find2</span><span class="p">()</span>
<span class="go">None</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mod2</span><span class="o">.</span><span class="n">find</span><span class="p">()</span>
<span class="go">pkg.mod2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">find_current_module</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">&lt;module &#39;astropy.utils.misc&#39; from &#39;astropy/utils/misc.py&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mod1</span><span class="o">.</span><span class="n">find_diff</span><span class="p">()</span>
<span class="go">pkg.mod1</span>
</pre></div>
</div>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper"><h3>Page Contents</h3>
<ul>
<li><a class="reference internal" href="#">find_current_module</a></li>
</ul>


        </div>
      </div>
      <div class="clearer"></div>
    </div>
<footer class="footer">
  <p class="pull-right">
    <a href="../_sources/_generated/astropy.utils.misc.find_current_module.txt"
       rel="nofollow">Page Source</a> &nbsp;
    <a href="#">Back to Top</a></p>
  <p>
    &copy; Copyright 2011-2013, The Astropy Developers.<br/>
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. &nbsp;
    Last built 22 Oct 2013. <br/>
  </p>
</footer>
  </body>
</html>