心即理、知行合一、致良知 with python

无善无恶是心之体,有善有恶是意之动,知善知恶是良知,为善去恶是格物

python 复制代码
class Goodness:
    def __init__(self, knowledge):
        self.knowledge = knowledge

    def reflect(self):
        print("Reflecting on the goodness of knowledge...")
        if self.knowledge:
            print("The knowledge is good.")
        else:
            print("The knowledge is lacking.")

class Nature:
    def __init__(self, object_name):
        self.object_name = object_name

    def observe(self):
        print(f"Observing the nature of {self.object_name}...")
        # Here you can add more complex observations or behaviors based on the nature of the object


def main():
    # Instantiate a Goodness object representing the goodness of knowledge
    goodness_of_knowledge = Goodness(knowledge=True)
    # Reflect on the goodness of knowledge
    goodness_of_knowledge.reflect()

    # Instantiate a Nature object representing the nature of a specific object
    nature_of_object = Nature(object_name="Python code")
    # Observe the nature of the object
    nature_of_object.observe()

if __name__ == "__main__":
    main()

加上装饰器

python 复制代码
def emphasize(func):
    def wrapper(*args, **kwargs):
        print("-" * 30)
        func(*args, **kwargs)
        print("-" * 30)
    return wrapper

class Goodness:
    def __init__(self, knowledge):
        self.knowledge = knowledge

    @emphasize
    def reflect(self):
        print("Reflecting on the goodness of knowledge...")
        if self.knowledge:
            print("The knowledge is good.")
        else:
            print("The knowledge is lacking.")

class Nature:
    def __init__(self, object_name):
        self.object_name = object_name

    @emphasize
    def observe(self):
        print(f"Observing the nature of {self.object_name}...")
        # Here you can add more complex observations or behaviors based on the nature of the object


def main():
    # Instantiate a Goodness object representing the goodness of knowledge
    goodness_of_knowledge = Goodness(knowledge=True)
    # Reflect on the goodness of knowledge
    goodness_of_knowledge.reflect()

    # Instantiate a Nature object representing the nature of a specific object
    nature_of_object = Nature(object_name="Python code")
    # Observe the nature of the object
    nature_of_object.observe()

if __name__ == "__main__":
    main()
相关推荐
zzywxc7879 分钟前
详细探讨AI在金融、医疗、教育和制造业四大领域的具体落地案例,并通过代码、流程图、Prompt示例和图表等方式展示这些应用的实际效果。
开发语言·javascript·人工智能·深度学习·金融·prompt·流程图
关山15 分钟前
MCP实战
python·ai编程·mcp
浮灯Foden22 分钟前
算法-每日一题(DAY13)两数之和
开发语言·数据结构·c++·算法·leetcode·面试·散列表
悠哉悠哉愿意31 分钟前
【Python语法基础学习笔记】if语句
笔记·python·学习
淡海水35 分钟前
【原理】Struct 和 Class 辨析
开发语言·c++·c#·struct·class
Q_Q196328847540 分钟前
python的电影院座位管理可视化数据分析系统
开发语言·spring boot·python·django·flask·node.js·php
BYSJMG1 小时前
计算机大数据毕业设计推荐:基于Hadoop+Spark的食物口味差异分析可视化系统【源码+文档+调试】
大数据·hadoop·分布式·python·spark·django·课程设计
杜子不疼.1 小时前
《Python学习之第三方库:开启无限可能》
开发语言·python·学习
青川入梦1 小时前
MyBatis极速通关上篇:Spring Boot环境搭建+用户管理实战
java·开发语言·mybatis
CC__xy2 小时前
04 类型别名type + 检测数据类型(typeof+instanceof) + 空安全+剩余和展开(运算符 ...)简单类型和复杂类型 + 模块化
开发语言·javascript·harmonyos·鸿蒙