栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号