Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's just personal preference really, and has to do with the layout of your python modules.</p> <p>Let's say you have a module called <code>erikutils</code>. There are two ways that it can be a module, either you have a file called <em>erikutils.py</em> on your <code>sys.path</code> or you have a directory called <em>erikutils</em> on your <code>sys.path</code> with an empty <em><code>__init__.py</code></em> file inside it. Then let's say you have a bunch of modules called <code>fileutils</code>, <code>procutils</code>, <code>parseutils</code> and you want those to be sub-modules under <code>erikutils</code>. So you make some .py files called <em>fileutils.py</em>, <em>procutils.py</em>, and <em>parseutils.py</em>:</p> <pre><code>erikutils __init__.py fileutils.py procutils.py parseutils.py </code></pre> <p>Maybe you have a few functions that just don't belong in the <code>fileutils</code>, <code>procutils</code>, or <code>parseutils</code> modules. And let's say you don't feel like creating a new module called <code>miscutils</code>. AND, you'd like to be able to call the function like so:</p> <pre><code>erikutils.foo() erikutils.bar() </code></pre> <p>rather than doing</p> <pre><code>erikutils.miscutils.foo() erikutils.miscutils.bar() </code></pre> <p>So because the <code>erikutils</code> module is a directory, not a file, we have to define it's functions inside the <em><code>__init__.py</code></em> file.</p> <p>In django, the best example I can think of is <code>django.db.models.fields</code>. ALL the django *Field classes are defined in the <em><code>__init__.py</code></em> file in the <em>django/db/models/fields</em> directory. I guess they did this because they didn't want to cram everything into a hypothetical <em>django/db/models/fields.py</em> model, so they split it out into a few submodules (<em>related.py</em>, <em>files.py</em>, for example) and they stuck the made *Field definitions in the fields module itself (hence, <em><code>__init__.py</code></em>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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