Cython,受保护的属性
我需要修改另一个实例中 C
实例的非公共属性。
cdef class C:
cdef C superC
cdef MakeToSuper(self, C other):
other.superC = C
protected
可能会在 C 中实现这一点,但是如何在 Cython
中实现这一点?
I need to modify a non-public attribute of an instance of C
within another instance.
cdef class C:
cdef C superC
cdef MakeToSuper(self, C other):
other.superC = C
protected
would probably do the trick in C, but how can I achive this in Cython
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过吗?
对于“请勿触摸它”消息(好吧,只有Python程序员会理解它,但总比没有好)。
还有
双下划线就像Python中的“私有”(但如果使用适当的Python机制仍然可以访问)。
选择 __ (双下划线),并使用一些 python 魔法在类的其他实例中访问它。它仍然可以通过任何其他 python 代码的相同魔法来访问,但每个知道如何绕过它的人也知道它的存在是有原因的。
Did you tried?
For "do not touch it pls" message (ok, only python programmers will understand it, but its better than none).
There is also
Double underscore is like "private" in Python (but still can be accessed if used proper Python mechanisms).
Go for __ (double underscore), and use some python magic to access it in other instances of your class. It will still be accessible by the same magic from any other python code, but everyone who knows how to bypass it knows also that it is there for a reason.