Key Import Issues

I have some questions about the Python instruction import:

  • What is the difference between import <module>and from <module> import *?

  • How to import a module that is not in the same directory? (not c PythonHome)

Please think I'm a Python newbie

+3
source share
2 answers

importimports the module into the global namespace. from importimports named elements into the namespace.

So, with a simple one, importyou always need to reference the module:

>>> import datetime
>>> day = datetime.date.today()

But with the help from importyou can directly refer to the elements:

>>> from datetime import date
>>> day = date.today()

from somemodule import *, . , . , , , , , , .

- PYTHONPATH.

+6

Source: https://habr.com/ru/post/1757321/


All Articles