In some Python scripts I see the following imports:
import fileA
import someDir.fileB
from fileC import functionA
There exist corresponding files fileA.py
, someDir/fileB.py
and fileC.py
. However, while looking in the Requests source code, I found this in the __init__.py
file:
from requests.packages.urllib3.contrib import pyopenssl
In this case, requests
is the CWD and packages.urllib3.contrib.pyopenssl.py
is the file. Why does this defy convention? I do see that the packages.urllib3.contrib
directory does also have a __init__.py
file, which seems to be related.
Furthermore, I'm not sure if it is related but I think it is so I post it here. In my script I have the folder kennethreitz/requests
, since the application depends on the Requests module but I'm deploying it to environments which might not have Requests installed. However, simply adding to the file import kennethreitz.requests
is not including the Requests module. I import kennethreitz.requests.__init__
and a few other obvious permutations but I cannot get the module to import. How can I package Requests with my code? The obvious Google searches are not helping.