Python-一般的なモジュール

モジュール:Pythonでは、xxx.pyはモジュールです

一般的なシステム組み込みモジュールの使用
    |-数学
    |-ランダム
    | -uuid

    | --os

    | - SYS
    | -時間
    | -日時
    | -カレンダー
    | - hashlib
    | - HMAC
    | - BASE64
 

モジュールの
 
インポート方法             importxxxx import random
            import uuid、sys
import os.path as 
from package path import module name
from package
path.module name import method、class、variable from functools import partial

 

1、数学:

このモジュールは、主に数学と関連する計算のモジュールに使用されます

数学的計算を実行する
| -math.ceil(num)#
切り上げる| -math.floor(num)#
切り下げる| -math.abfs(num)#絶対値を見つける
| -math.modf(num)#整数部分と分数部分をタプルの形式で返します
| -math.pi#Pi
| -math.pow(num、num2)
#Power num ** num2 | -math.sqrt(num)#平方根     抽出
属性:
pi# ′榮率
    e#自然定数
メソッド:
    三角関数sin cos ...
    対数loglog10 ...
    ceil()#切り上げ
    floor()     #切り下げfabs
    #絶対値
sqrt#平方根
    パワー#パワー
 

2、

os.path模块
    'abspath'、 'altsep'、 'basename'、 'commonpath'、 'commonprefix'、
    'curdir'、 'defpath'、 'devnull'、 'dirname'、 'exists'、 'expanduser'、 
    'expandvars '、' extsep '、' genericpath '、' getatime '、' getctime '、' getmtime '、
    ' getsize '、' isabs '、' isdir '、' isfile '、' islink '、' ismount '、' join '、 
    'lexists'、 'normcase'、 'normpath'、 'os'、 'pardir'、 'pathsep'、 'realpath'、
    'relpath'、 'samefile'、 'sameopenfile'、 'samestat'、 'sep'、 'split '、
    ' splitdrive '、''splitext'、 'stat'、 'supports_unicode_filenames'、 'sys']

主にオペレーティングシステムのファイル管理システムを管理します
|
-chdir (path)#現在のワークスペースパスを変更します| -curdir#現在のワークスペースパス
| -os.getcwd()#パスの絶対パスを取得します| -os
。 path.abspath(path)#パスの絶対パスを取得します
| -os.cpu_count()#現在のコンピューターのCPUアーキテクチャを取得します
| -os.device_encoding(fd)#デバイスのコードを取得します
|- os.getpid()#プロセス番号を取得
| -os.getppid()#現在のプロセスの親プロセス番号を取得
| -os.kill()#プロセスを番号で
強制終了| -os.listdir(path )#パスとフォルダーの下にあるすべてのファイルをトラバースし、リストの形式で名前を返します
| -os.mkdir()#シングルレベルフォルダー(ディレクトリ)を
作成します| -os.makedirs()#マルチレベルを作成しますディレクトリ
| -os.name#オペレーティングシステム名を取得
| -os.rename()#名前を変更
| - os.remove()#削除ファイル
| - os.removes()#マルチレベルディレクトリを削除
| - os.rmdir()#削除ディレクトリ
| -現在のシステムに対応するos.sep#ファイルの分離文字
| -abspath#絶対パスを取得dirname + basename
| -altsep#ファイルセパレータ
 | -basename#ファイル| -dirname
 #所有ディレクトリ
 | -exists ()
 | -join ()| -split
 ( )    

3、os.path

| -os.path.abspath(path)#パスの絶対パスを取得します
| -os.path.altsep#パスセパレーター
| -os.path.basename(path)#に対応するファイル名を取得しますpath
| --os.path.dirname(path)#ファイルが配置されているディレクトリを取得します| -os.path.exists(path)#
ファイルが存在するかどうかを判断します
| -os.path.getatime(path)#ファイルの最終アクセス時刻を取得
| --os.path.getctime(path)#ファイル作成時刻を取得| -os.path.getmtime(path)#
ファイル変更時刻を取得 
| -os.path.getsize(path )#ファイルサイズを取得します。単位はB(バイト)です
| -os.path.isdir(path)#パスがディレクトリかどうかを判断します
| -os.path.isfile(path)#パスがファイルかどうかを判断します
| -os.path.isabs(path)#パスが絶対パスかどうかを判断します
| -os.path.islink(path)#パスがリンク(ソフトリンク、ハードリンク)かどうかを判断します
| -os .path.ismount(path)#パスがマウントファイル(Uディスク、CDドライブなど)であるかどうかを確認します
| -os.path.join(path1、path2)#パスの接続が完了すると、システムに応じてセパレータが自動的に生成されます
| -os.path.split(path)#ファイルパスを分離します
 

4、sys

    |     -argv
    #パラメータを渡すスクリプト
| -exit()#システムを終了します| -getdefaultencoding()#システムのデフォルトエンコーディングを取得します
    | -getfilesystemencoding()#ファイルエンコーディングを取得します
    | -setrecursionlimit(num) #再帰的な制限値を設定する
    | -getrecursionlimit()#再帰的な制限値を取得する
    | -getrefcount()#オブジェクトの参照カウントを取得する

5、ランダム

    random.random()#ランダム[0〜1)間隔
    random.randint()#[a、b]間隔内のランダムな整数
    random.uniform#[a、b]間隔内の
    乱数random.choice(container)#ランダム選択1つの要素
    random.shuffle(container)#シャッフル、ランダムにデータをシャッフルします

6、時間

 'sleep'、 'strftime'、 'strptime'、 'struct_time'、 'thread_time'、
   'thread_time_ns'、 'time'、 'time_ns'、 'timezone'、 'tzname']


    | -関数は、asctime()#戻り日付文字列 
    | - CTIME()#戻り日付文字列 
    | -のgmtime()#取得時刻オブジェクト
    | -のlocaltime()#取得時刻オブジェクト
    | -時間() #現在のタイムスタンプを取得     | -sleep(
    sec)#スリープ
    |
-strftime()#時刻をフォーマット| -strptime()#文字列フォーマット時刻を日付オブジェクトに変換

7、日時

    | -time([hour [、minutes] [、seconds]])#時間オブジェクトを作成します
    | -date(year、month、day)#日付オブジェクトを作成します
    | -datetimeサブモジュール

    

8、日時サブモジュール

    import datetime
        datetime.datetime.xxxx()
    from datetime import datetime

    'astimezone'、 'combine'、 'ctime'、 'date'、 'day'、 'dst'、 'fold'、
    'fromisocalendar'、 'fromisoformat'、 'fromordinal'、 'fromtimestamp'、
    'hour'、 'isocalendar '、' isoformat '、' isoweekday '、' max '、' microsecond '、' min '、' minutes '、' 
    month '、' now '、' replace '、' resolution '、' second '、
    ' strftime '、 'strptime'、 'time'、 'timestamp'、 'timetuple'、 'timetz'、 
    'today'、 'toordinal'、 'tzinfo'、 'tzname'、 'utcfromtimestamp'、 
    'utcnow'、 'utcoffset'、 'utctimetuple '、'平日 '、'年 ']

| - astimezone(时间オブジェクト)#戻り、現在の時間帯に対応する時刻オブジェクト
| - datetime.now()#戻り、現在時刻オブジェクト
| - ctimeのヨーロッパやアメリカを満たしている(时间オブジェクト)#Aは時刻文字列標準
| -time (時間オブジェクト)#時間オブジェクトの時間部分を
返します
| -date (時間オブジェクト)#時間オブジェクトの日付部分を返します|-日#週
|-今#time
|-分#minute
| -二#second
| -マイクロ秒#マイクロ秒

9、カレンダーモジュール

カレンダーモジュール

10、hashlib

暗号化:
        同じ秘密鍵を渡す場合は、暗号化アルゴリズムを変更できます。
            |-対称暗号化
                DES

            |-非対称暗号化
                の秘密鍵と復号化鍵は、同じ
                rsaを使用して
                秘密鍵、公開鍵、秘密鍵のペア生成するために使用されません
            
            |-ハッシュ暗号化(ハッシュ)、ハッシュ暗号化、
                不可逆暗号化、一方向、結果は唯一の
                md5
                shal256shal384
                です

11、hmac

    import hmac
    m = hmac.new( "123456" .encode( "utf-8")、 "liujianhong" .encode( "utf-8")、 "MD5")
    m.hexdigest()

12、uuid:

ユニーク

import uuid
s = uuid.uuid4()
s.hex
 

 

 

おすすめ

転載: blog.csdn.net/weixin_45802686/article/details/109151278