1. The module is also a Python object with a random name attribute used to bind or reference.
Simply put, a module is a file that holds Python code. Modules can define functions, classes, and variables. Executable code can also be included in the module.
Example
The Python code in a module called Aname is usually found in a file called aname.py. The following example is a simple module support.py.
def print_func (PAR):
print "Hello:", par
return
2.import statement
To use the Python source file, you only need to execute the import statement in another source file, the syntax is as follows:
Import module1[, module2[,... Modulen]
When the interpreter encounters an import statement, the module is imported if it is in the current search path.
The search path is a list of all directories that the interpreter will search first. If you want to import module support.py, you need to put the command at the top of the script:
#!/usr/bin/python
#-*-coding:utf-8-*-
# Importing modules import
Support
# Now you can call the functions contained in the module
support.print_ Func ("Zara")
3.globals () and locals () functions
Depending on where the call is made, the globals () and locals () functions can be used to return names in the global and local namespaces.
If you call locals () inside a function, it returns all the names that can be accessed in that function.
If you call Globals () inside a function, it returns all the global names that can be accessed in the function.
The return type of two functions is a dictionary. So the names can be extracted using the keys () function.