zoukankan      html  css  js  c++  java
  • Day 15 包与常用模块

    day15思维导图

    一 包 package

    Packages are a way of structuring Python’s module namespace by using “dotted module names”

    A package is a collection of Python modules, i.e., a package is a directory of Python modules containing an additional __init__.py file. The __init__.py distinguishes/dɪˈstɪŋɡwɪʃ/(分辨) a package from a directory that just happens to contain a bunch of Python scripts. Packages can be nested to any depth, provided that the corresponding directories contain their own __init__.py file.

    A package, in essence, is like a directory holding subpackages and modules. While we can create our own packages, we can also use one from the Python Package Index (PyPI) to use for our projects.

    __init__.py

    The package folder contains a special file called init.py, which stores the package's content. It serves two purposes:

    The Python interpreter recognizes a folder as the package if it contains init.py file. init.py exposes specified resources from its modules to be imported.

    An empty init.py file makes all functions from above modules available when this package is imported. Note that init.py is essential for the folder to be recognized by Python as a package. You can optionally define functions from individual modules to be made available.

    二 Logging module

    Standard Library Logging Module

    Python comes with a logging module in the standard library that provides a flexible framework for emitting(发出) log messages from Python programs. This module is widely used by libraries and is the first go-to point for most developers when it comes to logging.

    The module provides a way for applications to configure different log handlers and a way of routing log messages to these handlers. This allows for a highly flexible configuration that can deal with a lot of different use cases.

    Logging Levels

    When you set a logging level in Python using the standard module, you’re telling the library you want to handle all events from that level on up. If you set the log level to INFO, it will include INFO, WARNING, ERROR, and CRITICAL messages. NOTSET and DEBUG messages will not be included here.

    Conclusion

    It is not necessary to know all of these, because it can be copied and used directly

  • 相关阅读:
    Balance_01背包
    4 Values whose Sum is 0_upper_bound&&ower_bound
    Newspaper Headline_set(upper_bound)
    lower_bound和upper_bound算法
    Blocks_DP&&矩阵快速幂
    All X_数的快速幂
    Training little cats_矩阵快速幂
    Raising Modulo Numbers_快速幂取模算法
    Defining Python Source Code Encodings
    Python ord(char)
  • 原文地址:https://www.cnblogs.com/fengshili666/p/14237410.html
Copyright © 2011-2022 走看看