Imports


In [4]:
import sys
sp =sys.path[0]
print "'%s' (type: %s)" % (sp, type(sp))


'' (type: <type 'str'>)

sys.path contains the empty string as first element, which resolves to the folder where the script is executed. This is why we can import the modules lying next to this and below here.


In [2]:
import innerpackage
import mod1
import mod2

print mod1
print mod2.some_function
print mod2.someName


<module 'mod1' from 'mod1.pyc'>
<function some_function at 0x7f8ebbe0b578>
1

In [3]:
# the module inside the package is not imported automatically
print innerpackage.innermod


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-439c1c940c9d> in <module>()
      1 # the module inside the package is not imported automatically
----> 2 print innerpackage.innermod

AttributeError: 'module' object has no attribute 'innermod'

In [ ]:
import innerpackage.innermod

# now it is imported
print innerpackage.innermod