How to write a custom solution using a python package, modules etc
<p>I am writing a packacge foobar which consists of the modules alice, bob, charles and david.</p>

<p>From my understanding of Python packages and modules, this means I will create a folder foobar, with the following subdirectories and files (please correct if I am wrong)</p>

<pre><code>foobar/
  __init__.py
  alice/alice.py
  bob/bob.py
  charles/charles.py
  david/david.py
</code></pre>

<p>The package should be executable, so that in addition to making the modules alice, bob etc available as 'libraries', I should also be able to use foobar in a script like this:</p>

<p>python foobar --args=someargs</p>

<p><strong>Question1:</strong></p>

<p>Can a package be made executable and used in a script like I described above?</p>

<p><strong>Question 2</strong></p>

<p>The various modules will use code that I want to refactor into a common library. Does that mean creating a new sub directory 'foobar/common' and placing common.py in that folder?</p>

<p><strong>Question 3</strong></p>

<p>How will the modules foo import the common module ?
Is it 'from foobar import common' or can I not use this since these modules are part of the package?</p>

<p><strong>Question 4</strong></p>

<p>I want to add logic for when the foobar package is being used in a script (assuming this can be done - I have only seen it done for modules)</p>

<p>The code used is something like:</p>

<pre><code>if __name__ == "__main__":
  dosomething()
</code></pre>

<p>where (in which file) would I put this logic ?</p>
