Python Initial Contact--module __python

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.