开发者

Cython, protected attributes

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 Cytho开发者_开发百科n ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜