Import name conflicts

Tim Johnson tim at
Tue Apr 18 14:28:44 EDT 2017

Using python 2.7~

For testing and edification purposes:

I have a project which has a controllers package at the directory
level just below the root.

>From the top-level (root) of the project, I start my python

The packages is called 'controllers' and has a submodule named 'imp'

I do the following:
>>> a = __import__('imp')
>>> dir(a)
['C_BUILTIN', 'C_EXTENSION', 'IMP_HOOK', 'NullImporter',
# object a is the builtin imp module

Now I do 
>>> b = __import__('controllers.imp', fromlist=['controllers'])
>>> dir(b)

# object b is the imp module in the controllers package.
# I've resolved a potential name collision ...

Now, suppose a python upgrade provides a package called controllers
or there's some great third-party package available called

How do I access the 'global' controllers package?



More information about the Python-list mailing list