1. 程式人生 > 其它 >Python專案-構成和呼叫不同函式

Python專案-構成和呼叫不同函式

Python編寫工業級的應用

設計模式
專案結構
專案部署

Python編寫系統軟體和應用軟體

01註釋和文件
    註釋
	宣告
	文件 doc
     help() 函式和 __doc__ 屬性獲取指定成員的說明文件
02.異常處理系統
    預設異常處理器
	try....except....
	try....except....finally
	with...as
	assert
	traceback使用 異常的獲取與處理

03.標準單元測試框架
     pytest是一個非常成熟的全功能的Python測試框架
	 The pytest framework makes it easy to write small tests, 
	 yet scales to support complex functional testing for applications and librarie


04.日誌框架
    日誌都是非常重要的組成部分,它是反映系統執行情況的重要依據,也是排查問題時的必要線索
    選擇合理的日誌級別、合理控制日誌內容
	Logging should be simple and intuitive
	日誌的額外的靈活性伴隨著額外的負擔需要考慮

05.應用級別的效能監控系統
    AppMetrics is a python library used to collect useful run-time application’s metrics, 
	   based on Folsom from Boundary, 
	   which is in turn inspired by Metrics from Coda Hale.
   在python下獲取metrics效能指標
    Gauges  Counter Meters

呼叫不同函式

實現方式一

功能: 根據輸入條件的不同選擇執行不同的函式,函式的輸入引數一致
 解決方式:
    python通過字典選擇呼叫的函式-定義一個字典,根據字典的值來進行執行函式
  函式是一箇中要的物件,然後
  字典可以使用get方法來進行值的選取,或者使用[]
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# ---------------------------
# CreateTime: 2021/6/11 11:27
# FileName: main_eg
# Author:

def get_upper(input_str):
    return input_str.upper()


def get_lower(input_str):
    return input_str.lower()


functions_dict = {
    "lower": get_lower,
    "upper": get_upper,
}


def get_result(choice, input_str):
    name_func = functions_dict[choice]
    out_value = str(name_func(input_str))
    print(out_value)
    return out_value


if __name__ == "__main__":
    input_str_a = "Study"
    get_result("upper", input_str_a)