Python module datetime

Source: Internet
Author: User

The Python module, which is a python file that ends with a. Py, contains Python object definitions and Python statements. Modules allow you to logically organize your Python code snippets. Assigning the relevant code to a module will make your code better and easier to understand. Modules can define functions, classes, and variables, and modules can also contain executable code.

Import Module

In other files that require these features, you can reuse these functions and variables by importing the module. Generally used with module_name.fun_name, and Module_name.var_name. Such semantic usage makes the module look like a class or namespace, and module_name can be understood as a name qualifier. The module name is the file name minus the. py suffix. There are several ways to import modules:

1). Import PackageA.SubPackageA.ModuleA #使用时必须用全路径名

2). From Packagea.subpackagea import Modulea #以直接使用模块名而不用加上包前缀.

3). From PackageA.SubPackageA.ModuleA import Functiona #直接导入模块中的函数或变量

1. When using the import Item.subitem.subsubitem syntax, the item before the last item must be a package, and the last item can be a module or package, but not a class, function, or variable;

2. When using the From package import item, item can be either a child module or a child package of the package, or another name defined in the packet (such as a function, class, or variable); First Check if item is defined in the packet. However, if it is not found, it is assumed that item is a module and tries to load it and throws a Importerror exception when it fails.

3. From pacakge Import * if the __init__.py of the package defines a list variable named __all__, it contains the list of module names as the list of modules to be imported. If __all__ is not defined, this statement does not import all of the package's sub-modules, it only guarantees that packages are imported, and then imports all the names defined in the package.

A package is a hierarchical file directory structure that defines a Python application execution environment consisting of n modules or N sub-packages.

The following is done by Pycharm first set up a directory modules, then build a Python package main, and finally create a client. PY file. When you create a package file, main, the tool automatically creates a ___init__.py python file, which is required.





This article is from the "Dreamscape" blog, make sure to keep this source http://dyqd2011.blog.51cto.com/3201444/1980253

Python module datetime

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.