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)
原文地址:https://www.cnblogs.com/ytwang/p/14889795.html