Question.
I am a noob, what is the difference between this:
import selenium
And this
from selenium import webdriver.
Doesn't import selenium
automatically import webdriver
?
Question.
I am a noob, what is the difference between this:
import selenium
And this
from selenium import webdriver.
Doesn't import selenium
automatically import webdriver
?
Yes it does but the use is different.
When you type from selenium import webdriver
you can access it by typing webdriver
in your code.
But when you run import selenium
you can access webdriver
by typing selenium.webdriver
.
Sometimes you want to make clear where this function is from like in django urls I always type from . import views
so I can then type views.myfunction
in code.
For import selenium
, names are accessed via selenium.nameX
. You also have access to the entire selenium package.
With from selenium import webdriver
, you are importing only webdriver from the selenium package. You do not have access to the entire selenium package. In the second case, you also access names from webdriver via webdriver.nameX
, not selenium.webdriver.nameX
.
yes but if you just import selenium you would have to do selenium.webdriver.functionyouwant
instead of just webdriver.functionyouwant
When you type import package
, you can access module
by typing package.module
.
When you type from package import module
, you can access module
by typing module
and you can't use other modules in package package
.