【发布时间】:2018-10-18 21:33:52
【问题描述】:
我在尝试覆盖 StructuredNode 构造函数时遇到此错误,而它与文档中的代码几乎完全相同。
Traceback (most recent call last):
File "/Users/xiao/PycharmProjects/Fooga_New/test/tmp.py", line 48, in <module>
tmp_node = Item(test='test_test_test')
File "/Users/xiao/PycharmProjects/Fooga_New/test/tmp.py", line 45, in __init__
super(Item, self).__init__(self, *args, **kwargs)
File "/Users/xiao/PycharmProjects/python3_venv/lib/python3.6/site-packages/neomodel/core.py", line 203, in __init__
super(StructuredNode, self).__init__(*args, **kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
这是我的代码:
from neomodel import db, StructuredNode, StringProperty
db.set_connection('bolt://' + 'neo4j' + ':' + '5428' + '@' + '192.168.0.24' + ':' + '7687')
class Item(StructuredNode):
name = StringProperty(unique_index=True)
uid = StringProperty(unique_index=True)
def __init__(self, test, *args, **kwargs):
# self.product = product
kwargs["uid"] = 'g.' + str(test)
kwargs["name"] = test
super(Item, self).__init__(self, *args, **kwargs)
tmp_node = Item(test='test_test_test')
tmp_node.save()
我想知道我是否正确使用了这个?
谢谢。
【问题讨论】:
-
堆栈跟踪中的
tmp_node分配与您提供的代码中的分配不匹配(test的值明显不同)。请确保您提供的代码肯定会产生错误,并提供代码产生的确切错误,否则我们无法确定我们正在查看的代码确实存在您所看到的问题。 -
很抱歉。我已经进行了修改。