心即理、知行合一、致良知 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()
相关推荐
许野平19 分钟前
Rust: 利用 chrono 库实现日期和字符串互相转换
开发语言·后端·rust·字符串·转换·日期·chrono
也无晴也无风雨22 分钟前
在JS中, 0 == [0] 吗
开发语言·javascript
狂奔solar31 分钟前
yelp数据集上识别潜在的热门商家
开发语言·python
Tassel_YUE32 分钟前
网络自动化04:python实现ACL匹配信息(主机与主机信息)
网络·python·自动化
聪明的墨菲特i39 分钟前
Python爬虫学习
爬虫·python·学习
blammmp1 小时前
Java:数据结构-枚举
java·开发语言·数据结构
何曾参静谧1 小时前
「C/C++」C/C++ 指针篇 之 指针运算
c语言·开发语言·c++
暗黑起源喵1 小时前
设计模式-工厂设计模式
java·开发语言·设计模式
WaaTong2 小时前
Java反射
java·开发语言·反射
Troc_wangpeng2 小时前
R language 关于二维平面直角坐标系的制作
开发语言·机器学习