心即理、知行合一、致良知 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()
相关推荐
liliangcsdn2 分钟前
因子权重矩阵处理-滞回缓冲带+降频稳定化动态重选
开发语言·python·算法
ShuiShenHuoLe4 分钟前
golang-jwt v5 入门
开发语言·后端·golang
泡泡鱼(敲代码中)20 分钟前
Python语法技术学习笔记
开发语言·笔记·python·学习·pycharm
CTA终结者26 分钟前
量化实现难,先看交易想法有没有说清
人工智能·python
hqyjzsb1 小时前
Python 技术人转型 AI:CAIE Level I、Level II 对比怎么选
开发语言·人工智能·python·金融·数据挖掘·数据分析·aigc
zhangzeyuaaa1 小时前
Python asyncio 事件循环演进:从手动管理到现代化实践
java·服务器·python
Yanjun2i1 小时前
Agent学习记录三:完成 Agent Loop
python·学习·agent
郝学胜_神的一滴1 小时前
Effective Python 条款 8: 同时遍历多组序列:zip 与 zip_longest 的实战避坑指南
python·pycharm
承渊政道1 小时前
【Python编程—从入门到实践】(Python字典:从基础语义到现代工程实践)
开发语言·python·pycharm·字典·嵌套
麻雀飞吧2 小时前
搜索“近期量化入门”时,先补交易理解再看 Python 和 API
人工智能·python