1

I can't understand how the python import works for big projects on the Github. Everyone knows the import statement - "from packageName import moduleName". But for some big projects, for example Django. I've got tutored "from django.urls import path". (https://docs.djangoproject.com/en/3.2/topics/http/urls/) But couldn't find any path.py file under /django/urls directory from its Github structure. (https://github.com/django/django/tree/main/django/urls) Did I miss any advanced import mechanism?

Nik_Lo
  • 11
  • 1
  • 1
    Does this answer your question? [What's the difference between a Python module and a Python package?](https://stackoverflow.com/questions/7948494/whats-the-difference-between-a-python-module-and-a-python-package) – Ankit Tiwari Nov 28 '21 at 06:33

1 Answers1

1

If you look at __init__.py, it imports the name path from conf.py. This makes path available as a variable in the django.urls module which can be imported.

rchome
  • 2,623
  • 8
  • 21
  • Is it a regular way to collect to-export module names with a \_\_all__ array in the \_\_init__.py file? And any recommended tutorials for this? I couldn't find it from those for beginners! :( – Nik_Lo Nov 28 '21 at 07:08
  • I'm definitely not any kind of expert on this subject, but I found some documentation you could read up on. https://docs.python.org/3/tutorial/modules.html#importing-from-a-package. It seems like the `__all__` list allows the module to explicitly specify which variables and packages get imported when you `import *` from that module. – rchome Nov 28 '21 at 07:19
  • rchome, you did me a big favor, thanks a lot. – Nik_Lo Nov 28 '21 at 07:30