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 ...
随机推荐
- Android学习笔记(十)——使用意图链接活动
使用意图链接活动 1.新建一个名为"UsingIntent"的项目,右击src目录下的包名,选择New-->Class选项.并将新的类文件名称命名为"SecondA ...
- 简单的glib测试(三)
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <locale.h&g ...
- HDU 1032.The 3n + 1 problem【注意细节】【预计数据不强】【8月21】
The 3n + 1 problem Problem Description Problems in Computer Science are often classified as belongin ...
- PCH in Xcode 6
本文转载至 http://blog.csdn.net/wbdwsqwwn/article/details/40476151 新建文件 ⌘+N 选择 iOS/Mac -> Other -> ...
- 文件管理中心iOS APP (国外市场:File Center) 技术支持
文件管理中心iOS APP (国外市场:File Center) 技术支持网址:http://www.cnblogs.com/flychen/邮箱:592802944@qq.com
- MapReduce算法形式五:TOP—N
案例五:TOP—N 这个问题比较常见,一般都用于求前几个或者后几个的问题,shuffle有一个默认的排序是正序的,但如果需要逆序的并且暂时还不知道如何重写shuffle的排序规则的时候就用以下方法就行 ...
- CarbonData
CarbonData http://carbondata.apache.org/ Apache顶级项目CarbonData应用实践与2.0新技术规划介绍_搜狐科技_搜狐网 https://www.so ...
- Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry
B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Tomcat启动报:invalid LOC header (bad signature)的问题
原因:这种一般是因为项目依赖的某个jar包损坏引起的, 解决办法: 1.右键项目,选择maven,更新(update maven project) 2.通过右击项目名 -> Run as -& ...
- [Android6.0][RK3399] 修改默认按键 KEY-PAD 的功能【转】
本文转载自:http://m.blog.csdn.net/dearsq/article/details/70175637 Platform: RK3399 OS: Android 6.0 Kernel ...