import package5 #(python)when package5 = directory!

Python import statement has many trivial or non-trivial scenarios. Here are some common ones:

Common scenario 1: we “import modu2” to execute modu2.py and also exposes all the “public” objects and functions in modu2 as modu2.something

(Simplest scenario but still not known to some programmers.)

Common scenario 2: if pack3 is a directory containing some python modules, we can
“import pack3.modu5” or “from pack3 import modu5”. Easy to understand.

Here’s a relative unusual scenario:

./pip install --verbose --no-deps --index-url=http://ficlonapd05.macbank:9090/api/ pymodels-linux==0.0.1.480 # assuming 0.0.1.480 is the pymodels version to test

./python
>>> import pymodels
>>> pymodels.__file__
'/home/tcrmg/vtan7/myenv/lib/python2.6/site-packages/pymodels/__init__.pyc'
>>> pymodels.BlackImplyVol(.2, 3,3, 1, 0, 1,1)

In this case, there’s a pymodels directory but BlackImplVol is a function in the compiled library ./pymodels/pymodels_imp.so. How is this function accessible?

A: when “import pymodels” is run, the ./pymodels/__init__.py script executes, which does  “from pymodels_imp import * “

Advertisements
Posted in py

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s