Python Forum
Question about dot notation syntax (Django source)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about dot notation syntax (Django source)
#4
Modules can become large and the author of such a module can use packages
to structure their modules. The python 3 documentation has a top quality
explanation of packages 6.4 Packages[

I have written do nothing code that might give you a better idea of what is
happening. I have created the following folder/file structure. Each
directory I placed an empty __init__.py file permitting me to use the
directory names as if they are packages.


Quote: foo
├── bar
│   ├── baz
│   │   ├── __init__.py
│   │   └── qux
│   │   ├── __init__.py
│   │   └── qux.py
│   └── __init__.py
├── foo.py
└── __init__.py

./foo/foo.py

    from .bar.baz.qux import Qux

    myQux = Qux()
    myQux.doNothing()
./foo/bar/baz/quz/qux.py

    class Qux:
      def __init__(self, name):
        self.name = name
      def doNothing(self):
        pass
While writing my foo.py module I remembered that I made a class inside
another module qux.py that I wish to use, particularly its method
doNothing() In this case, I can import that code using the dot notation,
because each of my subfolders are serving as containers or rather packages
of other useful modules. In this particular case our bar module is not
installed in the system packages so I prefix bar with .bar as to reference
the current directory.

What I am trying to demonstrate here is that the dots don't always refer to
other packages, they can refer to classes and functions as well. It all
depends on how the code is structured. Not sure if this helps or if it
complicates your current understanding.
Reply


Messages In This Thread
RE: Question about dot notation syntax (Django source) - by knackwurstbagel - Feb-25-2018, 02:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,339 Jun-30-2019, 12:21 AM
Last Post: scidam
  Python requests.get() returns broken source code instead of expected source code? FatalPythonError 3 3,738 Sep-21-2018, 02:46 PM
Last Post: nilamo
  Django syntax mepyyeti 2 2,498 Feb-16-2018, 05:03 AM
Last Post: Drone4four
  Django question tony1812 1 3,314 Aug-28-2017, 01:13 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020