Modules and Packages (official website https://docs.python.org/3/contents.html) 1. Modules1.1 A. py file (usually defined as a function or data or method) can be called as a moduleThe 1.2 module can contain executable statements and definitions of functions that are intended to initialize modules that are executed only when the module name is first encountered importing import statements (the import stateme
Introduction to a Python modulePython module:A code-heavy program can be segmented into several pieces of code that are organized, independent but interacting with each other, and these self-contained, organized snippets of code are modulesThe module behaves as a code file that ends in. py in physical formA file is seen as a standalone module, and a module can be viewed as a fileThe file name of the module is the name of the module plus the extension.
The hashlib and base64 encryption modules in python use instances, and hashlibbase64
I have seen several bloggers learn python by breaking through each module. I also follow this example. This article describes the modules involved in python encryption.
Hashlib
The hashlib m
This entry collects common database interface modules in Python, including various mainstream relational databases and some common interfaces.
Unless otherwise specified, all (or partially implemented) The DB-API standards.
For more extensive Python database technology, see Python database development overview.
1. D
In order to write maintainable code, we grouped many functions into separate files so that each file contained relatively few code, and many programming languages used this way of organizing code. In Python, a. py file is called a module.Why use a module?Similar to the C language:1, greatly improve the maintainability of the Code;2, very versatile code can be reused, can be referenced by a third party;3, different
The Ython Pickle module acts as a persistent storage data.Often encountered in the Python program run to get some strings, lists, dictionaries and other data, want to save for a long time, easy to use later, rather than simply put in memory shutdown power loss data. The pickle module in the Python module is useful for converting objects into a format that can be
Python Common module Two
ShelvePickleJson
Shelve module
The internal structure is actually the dictionary type, the storage time specifies the corresponding key, the content is stored as value, and takes out the value directly through key.
Note that the file name does not require any suffixes because the system defaults to. db as the suffix name.
Code 1 storing content
import shelvedef fun1(): pass= shelve.open(‘
We saw the functions and objects before. In essence, they are all for the better organization of existing procedures to facilitate reuse.
Modules (module) are also intended for the same purpose. In Python, a. py file forms a module. Through modules, you can invoke programs in other files.
Introducing Modules
We firs
of the PYTHONPATH environment variable Sys.modules.keys () to return the list of all modules that have been imported Sys.modules returns the module field of the system import, key is the module name, and value is the module sy S.exc_info () Gets the exception class currently being processed, Exc_type, Exc_value, exc_traceback the exception details currently handled Sys.exit (n) exit the program, exit normally (0 Sys.hexversion gets the version value
to implement
There is no doubt that it is safer to fail the program accidentally because of some minor negligence.
Try: Except this exception handling mechanism is to replace if that way, allowing your program to enhance robustness and fault tolerance without sacrificing readability
Exception types are customized for each exception (Python unifies classes and types, type is a Class), and for the same exception, a except can be
In general, we will write our own Python module and Python's own modules stored separately to achieve easy maintenance purposes. The Python runtime environment is a sys.path list when looking for a module, and if we want to add a custom module to the runtime, there are three main ways to do this: 1. Add a new path to the Sys.path list (only works for the current
Modules (module)Python has a concept called module, which is similar to a header file in C and a package in Java, such as in Python to invoke the SQRT function, which must be introduced into the math module with the Import keyword. In layman's terms, a module is like a toolkit, and if you want to use the tool in the toolkit (like a function), you need to import t
mystuff[' Apple '] remember this concept of "get X from Y", now look at the module, you've created and used some of the modules, and you've seen some of their properties: 1. A module is a Python file that contains functions and variables. 2. You can import this file. 3. You can then use the '. ' operator to access the functions and variables in the module. If I had a module named mystuff.py and put a funct
Example of the usage of the time and datetime modules in Python, pythondatetime
Time module method:Time. time (): Get the timestamp of the current time
Time. localtime (): receives a timestamp and converts it to a tuples of the current time. If no parameter is specified, time. time () is input as the parameter by default.
Time. localtime ():
Index
Attribute
Descrip
After years of using Python, I stumbled upon features and features that we didn't know in the past. Some can be said to be very useful, but they are not fully utilized. With that in mind, I've edited some of the features of Python that you should know about.
Functions with any number of parametersYou may already know that Py
The Python language feature is very powerful, in addition to the class, there is the concept of modules and packages, which is a bit like Perl, here is a brief talk about packages and modules.
First, the module in Python
Module-is actually what we call the concept of Library (Lib), but it can not only contain a series
Modules and PackagesAs we all know, in the process of computer program development, as the program code more write more, so that the code will be less easy to maintain.Sometimes, in order to maintain code, the functions of different functions are placed in different xx.py files.In Python, a. py file is called a module.What are the benefits of using modules?1, to
First, the moduleThe module is essentially a python file , which is used to organize the code, meaning that the python code is written inside, the filename is the name of the module, test.py Test is the module name. Import module of the essence is to import the module inside the code, from the top to the bottom of the order to find the module is, first from the current directory to find, can not find the w
What is a module模块是一系列功能的集合体常见的模块形式(自定义模块、第三方模块、内置模块): 1、一个module.py文件就是一个模块,文件名是module.py,而模块名是module 2、一个包含有__init__.py文件的文件夹也是模块 3、已被编译为共享库或DLL的C或C++扩展 4、使用C编写并链接到python解释器的内置模块Why use a module1、用第三方或者内置的模块是一种拿来主义,可以极大地提升开发效率2、自定义模块即将我们自己程序中需要用到的公共的功能写入一个python文件 然后程序的各部分组件可以通过导入的方式来引用/重用自定义模块中的功能How to use Modules 大前提:模块是被执行文件导入使用,模块的导入必须搞明白
1 The composition of the Python extension moduleIn Python, this module is typically C for some system-related modules or for modules with high performance requirements. The following sections are mainly included in the extension module:
The init function, which is called the init+ module name, is responsible f
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.