Python Basics Module

Source: Internet
Author: User

Python Basics Module

A module is a file that contains the Python definition and declaration, and the filename is the suffix of the module name plus the. Py.

is a python file that defines classes and methods, implements functions that can be called by other Python files

So how do you use a module?

Of course, using the Import module name this way to load a module, such as: Import time

If you want to use a class in a module, it is:

Module name, such as: Import Modle. Teacher

So what if the method in the module doesn't know what to do with it?

Two methods:

1.help (module name. Class)

2.Ctrl + Left button click Class

So how do you make a call module across directories?

Hierarchical structure:
Dir1
---hello.py
Dir2
---main.py
Among them, hello.py:
def add (x, y):
Return X+y
How main.py can be called to the Add function in hello.py.

This is still very simple:

  Import sys  sys.path.append ("D:/dir1") #添加你要导入的模块的路径, note: The path to run is based on the file you executed!!!  Import Hello  print (hello.add)

Python Basics Module

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.