如何在Python中模拟赋值运算符重载?

如何在Python中模拟赋值运算符重载?,第1张

如何在Python中模拟赋值运算符重载?

我最终创建了一个名为Modelmeta的Model元类,该元类注册了类型化的属性

参见http://github.com/espeed/bulbs/blob/master/bulbs/model.py

在这种情况下,类型化的属性是图形数据库“属性”,它们都是Property类的所有子类。

参见https://github.com/espeed/bulbs/blob/master/bulbs/property.py

这是一个示例模型声明:

# people.pyfrom bulbs.model import Node, Relationshipfrom bulbs.property import String, Integer, DateTimefrom bulbs.utils import current_datetimeclass Person(Node):    element_type = "person"    name = String(nullable=False)    age = Integer()class Knows(Relationship):    label = "knows"    created = DateTime(default=current_datetime, nullable=False)

用法示例:

>>> from people import Person>>> from bulbs.neo4jserver import Graph>>> g = Graph()# Add a "people" proxy to the Graph object for the Person model:>>> g.add_proxy("people", Person)# Use it to create a Person node, which also saves it in the database:>>> james = g.people.create(name="James")>>> james.eid3>>> james.name'James'# Get the node (again) from the database by its element ID:>>> james = g.people.get(james.eid)# Update the node and save it in the database:>>> james.age = 34>>> james.save()# Lookup people using the Person model's primary index:>>> nodes = g.people.index.lookup(name="James")

看到…

  • 灯泡模型API:http://bulbflow.com/docs/api/bulbs/model/
  • 灯泡模型快速入门:http://bulbflow.com/quickstart/#models


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5673773.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存