Edit is done because my question was identified as a possible duplicate of another question asking difference between the two methods.
I'm new to python so was reading various opinions upon import
and from import
to cure my lack of knowledge. EDIT: I understood the difference it makes using either methods. To put it simply, import sth.sth_else
method creates a reference to sth.sth_else
, so we can access anything inside __init__().py
of sth_else
using sth.sth_else.func()
or sth.sth_else.var
. However, if from sth import sth_else
is used, then we need not use sth
with the [dot] opperator for scope resolution along with sth_else
. This time we can simply use sth_else.func()
and sth_else.var
. I got to know all this from the most voted answer of a question on stackoverflow on the difference between the two import methods. But even using these two different methods I was able to find a way using as
that the difference I got to know from the answer got insignificant/inappropriate. Meaning I was quite getting everything, until these two import methods started providing same invoking (which is different according to that answer), hence I was wondering if there is more to it than meets the eye..
import
Method:
>>> import tkinter.ttk as my
>>> my.Button()
<tkinter.ttk.Button object .!button>
>>>
from import
Method:
>>> from tkinter import ttk as my
>>> my.Button()
<tkinter.ttk.Button object .!button>
>>>
Now with the knowledge I have currently, I'd say these two importing methods are exactly the same in all aspects. But I'm not 100% sure of it being certain, so my question is: Are these two methods really exactly the same?