0

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?

Daniel Walker
  • 6,380
  • 5
  • 22
  • 45
  • 1
    Does this answer your question? [Use 'import module' or 'from module import'?](https://stackoverflow.com/questions/710551/use-import-module-or-from-module-import) –  Apr 24 '22 at 02:52

4 Answers4

2

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.

2

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.

1

yes but if you just import selenium you would have to do selenium.webdriver.functionyouwant instead of just webdriver.functionyouwant

bro
  • 51
  • 1
  • 11
1

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.