I'm getting a bit confused by how import works in Python (3.5). I thought that using something like "import x" would be just as writing whatever is written into "x.py", however it does not seem like it.
I have the following structure:
- main.py
- Package1
- module1.py
Now, just for completion, the module is:
## module1.py
import numpy as np
import matplotlib.pyplot as plt
def plot(x,y):
A = plt.figure()
plt.plot(x,y)
plt.show()
return A
So it really doesn't do anything that matplotlib.pyplot would not do. Now my main.py is just calling it like this:
## main.py
from Package1.module1 import plot
a= plot([1,2,3],[2,4,6])
And this works. So I'm assuming that it actually imports matplotlib.pyplot as plt, since otherwise the function plot would not work. However, if now I add anything to main.py such as plt.figure() or np.array(), it says that it does not recognize these.
So the actual question is... Have I imported matplotlib.pyplot to the main namespace? If not, is there a different namespace here? If there is, if I now wanted to use matplotlib in the main.py below that code, and I imported it again with import matplotlib.pyplot as plt, would I be importing it twice?
I am a bit lost in the hierarchy here.