python 单下划线和双下划线
underline.py
__all__ = ['_underline_variable', '__underline_variable', '_underline_func',
'__underline_func', '_underline_class', '__underline_class'] _underline_variable = 100
__underline_variable = 200 def _underline_func():
pass def __underline_func():
pass class _underline_class():
pass class __underline_class():
pass class Base():
def _underline(self):
pass def __underline(self): # 私有
pass class Derived(Base):
pass if __name__ == '__main__':
base = Base()
base._underline()
#base.__underline()
base._Base__underline() derived = Derived()
derived._underline()
#derived._Derived__underline()
derived._Base__underline()
test.py
# 1 用import方式导入
import underline print(underline._underline_variable)
print(underline.__underline_variable)
underline._underline_func()
underline.__underline_func()
test1 = underline._underline_class()
test2 = underline.__underline_class() print('*' * 20) # 2 没有定义__all__属性,用from ... import *方式导入
#from underline import *
#print(_underline_variable)
#print(__underline_variable)
#_underline_func()
#__underline_func()
#test1 = _underline_class()
#test2 = __underline_class() # 3 定义__all__属性,用from ... import *方式导入
from underline import *
print(_underline_variable)
print(__underline_variable)
_underline_func()
__underline_func()
test1 = _underline_class()
test2 = __underline_class()
python 单下划线和双下划线的更多相关文章
- python 里面的单下划线与双下划线的区别
python 里面的单下划线与双下划线的区别 Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __ ...
- Python里的单下划线,双下划线,以及前后都带下划线的意义
Python里的单下划线,双下划线,以及前后都带下划线的意义: 单下划线如:_name 意思是:不能通过from modules import * 导入,如需导入需要:from modules imp ...
- python单下划线、双下划线、头尾双下划线说明:
单下划线.双下划线.头尾双下划线说明: __foo__: 定义的是特殊方法,一般是系统定义名字 ,类似 __init__() 之类的. _foo: 以单下划线开头的表示的是 protected 类 ...
- 测试Python类成员的单下划线,双下划线,两头下划线的区别
首先原谅一个菜鸟叫他“两头下划线”.记得在windows编程中,很多宏定义使用下划线+大写,给人逼格很高的错觉.对于Python下划线的认识,大概是从__dict__这个属性开始的,看__dict__ ...
- Python笔记_第三篇_面向对象_4.单下划线和双下划线
说道这里我们需要稍微暂停一下.前面我们说到了类是作为一个对象存放容器.这个容器里面有属性和方法.最好的理解类的方式就是把类想想成一个容器. 然后构造了一个析构函数和构造函数,然后又对object和se ...
- python(七) Python中单下划线和双下划线
Python中单下划线和双下划线: 一.分类 (1).以单下划线开头,表示这是一个保护成员,只有类对象和子类对象自己能访问到这些变量. 以单下划线开头的变量和函数被默认是内部函数,使用from mod ...
- python中的单下划线和双下划线意义和作用
Python中并没有真正意义上的“私有”,类的属性的的可见性取决于属性的名字(这里的属性包括了函数).例如,以单下划线开头的属性(例如_spam),应被当成API中非公有的部分(但是注意,它们仍然可以 ...
- python单下划线与双下划线的区别
Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核心风格:避免用下划 ...
- python类中方法加单下划线、双下划线、前后双下滑线的区别
首先看一段代码: class Foo(): def __init__(self): print "__init__ method" def public_method(self): ...
- 【python】单下划线与双下划线的区别
Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 以单下划线开头(_f ...
随机推荐
- redux 及 相关插件 项目实战
目录结构 +-- app | +-- actions | +-- index.js | +-- components | +-- content.js | +-- footer.js | +-- se ...
- Unity ----- 对象池GameObjectPool
孙广东 2014.6.28 非常早之前看到的外国文章,认为不错,分享一下. 对象池在AssetStore中也是有非常多插件的,可是有些重了.自己写一个轻量的岂不是非常好. 当你须要创建大量某种类型对象 ...
- 写2个线程,其中一个线程打印1~52,另一个线程打印A~z,打印顺序应该是12A34B45C……5152Z
我写的 class LN { private int flag = 0; public static char ch = 'A'; public static int n = 1; public sy ...
- 在线API
JExcelApi http://jexcelapi.sourceforge.net/resources/javadocs/index.html Poi http://poi.apache.org/a ...
- android 项目R文件丢失解决的方法
R文件丢失的原因有非常多,这里提供几种解决的方法: 1. 选中项目,点击 Project - Clean , 清理一下项目. 2. 选中项目,右键 选择 Android Tools - Fix P ...
- C语言的一些特殊使用方法————————【Badboy】
一:特殊的字符串宏 [cpp] #define A(x) T_##x #define B(x) #@x #define C(x) #x 我们如果x=1, 则上面的宏定义会被解释成下面的样子 A(1)- ...
- UICollectionViewController xcode6.1 自定义Cell
本文转载至 http://blog.csdn.net/daleiwang/article/details/40423219 UICollectionViewContAutolayoutstoryboa ...
- 创建Vue项目的步骤
第一步: 对于要创建项目的工作目录,要先进性管理,命令:npm init -y 第二步: 初始化webpack 包,命令:vue init webpack 自定义名称 第三步: 在components ...
- awk基本语法
1 awk处理的对象 1.1 record awk处理时,默认会将文件按照换行符,分隔成record.默认分隔符是换行符. 1.2 filed 对于每个record,awk自动又分隔成filed.默认 ...
- feed流,图片在左还是右的区别是
feed流设计:那些谋杀你时间APP | 人人都是产品经理 http://www.woshipm.com/pd/773523.html