When I have a single file module relying on a 3rd party module or method from a 3rd party module which is imported in the single file module, then I have access to the 3rd party module or method when I import the single file module. I want to prevent that, my suggestion was to import the 3rd party module or method and renaming them with an underscore in front. Would that be a good idea, what other options do I have.
Example 1:
# this is a single file module called DemoModule.py
import numpy as np
def calculate_something():
x = np.cos(0)
return x
Now when I import DemoModule I do not only have access to calculate_something, but I also have access to everything numpy has to offer as well. Would this be a good way to avoid that situation:
# this is a single file module called DemoModule.py
import numpy as _np
def calculate_something():
x = _np.cos(0)
return x
Example 2:
# this is a single file module called DemoModule.py
from numpy import cos
def calculate_something():
x = cos(0)
return x
Now when I import DemoModule I do not only have access to calculate_something, but I also have access to cos. Would this be a good way to avoid that situation:
# this is a single file module called DemoModule.py
from numpy import cos as _cos
def calculate_something():
x = _cos(0)
return x
Edit:
A run from the command line
In[2]: import DemoModule
In[3]: DemoModule.np.cos(1)
Out[3]: 0.54030230586813977