Note that there are some explanatory texts on larger screens.

plurals
  1. PODifference between package simulating module, and real module
    primarykey
    data
    text
    <p>Lets assume we write some component, which will be distributed. Lets call it "worker". Worker should do some magic, but API is quite simple - 2 or 3 classes/functions. BUT insides of worker are quite big. We need non-API functions.</p> <p>End-user should be using it like this:</p> <pre><code>from worker import foo ... foo(x) </code></pre> <p>or</p> <pre><code>import worker ... worker.foo(x) </code></pre> <p>But foo uses "login" which takes lot of bit operations, hashing, encoding, etc, and "calculate" which uses hell lot of math expressions.</p> <p>So, now we have 2 options for code organisation:</p> <ol> <li><p>Only one module, called "worker" which will have API functions ("foo"), internal functions ("login", "calculate") and <code>__all__</code> variable with value <code>["foo", ...]</code>.</p></li> <li><p>We create package "worker", and split logic into submodules:</p> <pre><code>worker worker/__init__.py worker/api.py worker/login_related.py worker/calculate_related.py </code></pre> <p>and in <code>__init__.py</code> we put:</p> <pre><code>from worker.api import * </code></pre></li> </ol> <p>Now user shouldn't be able to tell if "worker" is module or package.</p> <p>But is he?</p> <p>I know, that <code>worker.__file__</code> will return path with <code>__init__.py</code> at the end. Also, qualified names of API functions will point to modules, not to package (unless I define them in <code>__init__.py</code>). What are other differences? How can one differentiate between "masked package" and module?</p>
    singulars
    1. This table or related slice is empty.
    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. 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