Using Dot Notation for Imported Objects
00:00
Now switch to main.py
. To access a name in an imported module from the calling module, type the imported module’s name followed by a dot, and then the name you want to use.
00:13
For instance, to use add()
on the adder
module, you need to type adder.add()
. So now the line looks value = adder.add()
, and then 2
and 2
as the arguments.
00:28
Save the file and run the module. Perfect. The value 4
is printed in the interactive window.
00:36
Here is what happened. When you type import adder
at the beginning of the main.py
Python file, the imported module’s entire namespace is added to the namespace of the calling module under the name of the imported module—so in this case, adder
.
Become a Member to join the conversation.