You need to import it using from. import http
However, at this point, you will not load the http.client module, and you will not be able to access it:
>>> http.client AttributeError: 'module' object has no attribute 'client'
There are various ways around this. The simplest thing is to do it in http/__init__.py
from . import client
Other things you can do is
import types http = types.ModuleType('http') from .http import client http.client = client
What can you do if it is not practical to modify http/__init__.py
However, since I assume that for some reason this will result in a replacement http.client with a replacement, I would recommend that you do this:
try: from .http import client except ImportError: from http import client
And then use the client name instead. This is by far the easiest and most beautiful solution.
Or, if you do not want to use the client as a name:
try: from .http import client as http_client except ImportError: from http import client as http_client
source share