我曾希望在 gremlin python 中将一个类映射到一个顶点就像这样简单:
def toVertex(self,g):
t=g.addV(type(self))
for name,value in vars(self).items():
if debug:
print("%s=%s" % (name,value))
t=t.property(name,str(value))
t.iterate()
为了避免任何类型强制问题,我认为 str(value) 将确保所有属性都被视为字符串。
不幸的是,我收到错误消息:
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gremlin_python/structure/io/graphsonV3d0.py", line 341, in dictify
return writer.toDict(typ())
TypeError: __init__() missing 1 required positional argument: 'record'
我在这里错过了什么 - 如何解决?
问题是该类型不返回字符串而是一个类,并试图调用需要记录的类的构造函数:
即使不使用 str() 作为值,以下代码也能工作:
def toVertex(self,g):
label=type(self).__name__;
t=g.addV(label)
for name,value in vars(self).items():
if debug:
print("%s=%s" % (name,value))
t=t.property(name,value)
t.iterate()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句