Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's my answer:-</p> <p>My directory structure:-</p> <pre><code>calvin$ tree /Users/calvin/work/learn3/ /Users/calvin/work/learn3/ └── myspecialpackage ├── __init__.py ├── __init__.pyc ├── io.py ├── io.pyc └── main.py </code></pre> <p><code>__init__.py</code> is an empty file.</p> <p><code>io.py</code> is your custom module which conflicts with python3's io module.</p> <p><code>main.py</code> contains this bunch of example code:-</p> <pre><code>import os import sys # These two lines are not needed you are installing the `myspecialpackage` via pip/pypi and as setup.py script places "myspecialpackage" and all its contents in your python site-packages, which is already in PYTHONPATH. our_package_root = os.path.dirname(os.path.realpath(__file__)) sys.path.append(our_package_root) from myspecialpackage import io print(io.__file__) </code></pre> <p>And the imported <code>io</code> module will be the one in your <code>io.py</code> and not python3's module.</p> <p>As a bonus, using this methodology will allow us to have your custom <code>io.py</code> as well as python3's <code>io</code> module (if you so desire having your cake and eat it ;-)). You can deconflict the use of the namespace <code>io</code> like this:-</p> <pre><code>from myspecialpackage import io as my_special_io print(my_special_io.__file__) import io print(io.__file__) </code></pre> <p>Running <code>main.py</code> will then give you:-</p> <pre><code>In [3]: run myspecialpackage/main.py /Users/calvin/work/learn3/myspecialpackage ./myspecialpackage/io.py /Users/calvin/.virtualenvs/learn3/bin/../lib/python3.3/io.py </code></pre> <p>Take note of the comment I made above regarding </p> <pre><code>our_package_root = os.path.dirname(os.path.realpath(__file__)) sys.path.append(our_package_root) </code></pre>
    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. 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