心即理、知行合一、致良知 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()
相关推荐
常利兵5 分钟前
解锁Kotlin:数据类与密封类的奇妙之旅
android·开发语言·kotlin
来自远方的老作者8 分钟前
第7章 运算符-7.1 算术运算符
开发语言·数据结构·python·算法·算术运算符
tq6J5Yg1412 分钟前
windows10本地部署openclaw
前端·python
MwEUwQ3Gx16 分钟前
PHP 异步与多线程 从 TrueAsync 展望未来
开发语言·php
pl4H522a630 分钟前
Python 高效实现 Excel 转 TXT 文本
java·python·excel
数据知道37 分钟前
claw-code 源码详细分析:Compaction 前置课——上下文压缩在接口层要预留哪些旋钮,避免后期全局返工?
python·ai·claude code
不会写DN39 分钟前
Go中如何跨语言实现传输? - GRPC
开发语言·qt·golang
小邓睡不饱耶43 分钟前
花店花品信息管理系统开发实战:Python实现简易门店管理系统
服务器·python·microsoft
她说..1 小时前
Java 基本数据类型高频面试题
java·开发语言·jvm·spring boot
witAI1 小时前
手机生成剧本杀软件2025推荐,创新剧情设计工具助力创作
人工智能·python