在python中的“Friend”类 [英] "Friend"ing classes in python

查看:363
本文介绍了在python中的“Friend”类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何方法使类private(或任何 self .__ var 真的是)的某些变量,但可访问另一个类,像c ++中的朋友,除了在python?我不想要任何类中的变量被弄乱。我也不想将整个代码复制并转换为第二个代码。

is there any way to make certain variables in classes "private" (or whatever self.__var really is) but be accessible to another class, like friends in c++, except in python? i do not want the variables in either class being messed with. Nor do i want to copy the entire code over and convert it for the second code.

推荐答案

不,没有这样的

使用以单个下划线开头的名称,并告诉正在处理您项目的其他人员不要对他们访问的内容愚蠢。

Use names that start with single underscores and tell the other people working on your project to not be silly about what they access.

这篇关于在python中的“Friend”类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆