Python - Bulbs - Models - Class initialization

2024-04-26 00:13:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习如何使用灯泡模型,我有关于节点类初始化的问题。你知道吗

根据文件:

from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime

class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    age = Integer()

在将数据保存到节点之前,如何执行数据操作?你知道吗

我能表演一下吗

class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    if name == "Bar":
        name = "Foo"

或者我必须重写节点初始化?你知道吗

class Person(Node):

    element_type = "person"

    name = String(nullable=False)

    def __init__(self, name):
        if name == "Bar":
            self.name = "Foo"

Tags: namefromimportnodefalsestring节点type