天天看點

Py之utils:utils庫的簡介、安裝、使用方法之詳細攻略

utils庫的簡介

         有時你會一遍又一遍地寫一個函數;有時你會擡頭看天花闆,問“為什麼,Guido,為什麼标準庫不包括這個?”“嗯,我們也許不能回答這個問題。但是我們可以把這些功能集中到一個地方!

utils庫的安裝

pip install utils

Py之utils:utils庫的簡介、安裝、使用方法之詳細攻略

utils庫的使用方法

1、基礎用法

from utils import enum

class Colors(enum.Enum):

   RED = 0

   GREEN = 1

   # Defining an Enum class allows you to specify a few

   # things about the way it's going to behave.

   class Options:

       frozen = True # can't change attributes

       strict = True # can only compare to itself; i.e., Colors.RED == Animals.COW

                     # will raise an exception.

# or use the enum factory (no Options, though)

ColorsAlso = enum.enum("RED", "GREEN")