Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In python, it is a common practice to have a bunch of modules that implement various functions and then have one single module that is the point-of-access to all the functions. This is basically the <a href="http://en.wikipedia.org/wiki/Facade_Pattern" rel="nofollow noreferrer">facade pattern</a>.</p> <p>An example: say you're writing a package <code>foo</code>, which includes the <code>bar</code>, <code>baz</code>, and <code>moo</code> modules.</p> <pre><code>~/project/foo ~/project/foo/__init__.py ~/project/foo/bar.py ~/project/foo/baz.py ~/project/foo/moo.py ~/project/foo/config.py </code></pre> <p>What you would usually do is write <code>__init__.py</code> like this:</p> <pre><code>from foo.bar import func1, func2 from foo.baz import func3, constant1 from foo.moo import func1 as moofunc1 from foo.config import * </code></pre> <p>Now, when you want to use the functions you just do</p> <pre><code>import foo foo.func1() print foo.constant1 # assuming config defines a config1 variable print foo.config1 </code></pre> <hr> <p>If you wanted, you could arrange your code so that you only need to write</p> <pre><code>import foo </code></pre> <p>At the top of every module, and then access everything through <code>foo</code> (which you should probably name "globals" or something to that effect). If you don't like namespaces, you could even do</p> <pre><code>from foo import * </code></pre> <p>and have everything as global, but this is really not recommended. Remember: namespaces are one honking great idea!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload