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 ...
随机推荐
- 二:redis 的hash类型相关操作
=====================二种:hash类型================== 介绍:redis -> hash是一个string类型的field和value的映射表 hash ...
- 程序的载入和运行(五)——《x86汇编语言:从实模式到保护模式》读书笔记25
程序的载入和运行(五)--<x86汇编语言:从实模式到保护模式>读书笔记25 前面几篇博文最终把代码分析完了.这篇就来说说代码的编译.运行和调试. 1.代码的编译及写入镜像文件 之前我们都 ...
- js中cookie的使用具体分析
JavaScript中的还有一个机制:cookie,则能够达到真正全局变量的要求. cookie是浏览器 提供的一种机制,它将document 对象的cookie属性提供 ...
- c语言-01背包问题
01背包问题 问题:有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总和最大. 分析: 这是最基础的背包问题,特点是:每种物品仅有一件,可以选 ...
- C语言-计数排序
计数排序的基本思想是:统计一个数序列中小于某个元素a的个数为n,则直接把该元素a放到第n+1个位置上.当然当过有几个元素相同时要做适当的调整,因为不能把所有的元素放到同一个位置上.计数排序假设输入的元 ...
- npoi 加密 https://bbs.csdn.net/topics/380226272
终于解决了,.1.用excel新建一个文件作为模板,可以是空内容,在excel中对文件进行加密,如密码为:12345. 2.在NPOI读取前,调用:Biff8EncryptionKey.Current ...
- Eureka vs Zookeeper
著名的CAP理论指出,一个分布式系统不可能同时满足C(一致性).A(可用性)和P(分区容错性).由于分区容错性在是分布式系统中必须要保证的,因此我们只能在A和C之间进行权衡.在此Zookeeper保证 ...
- http协议的队首阻塞
1 队首阻塞 就是需要排队,队首的事情没有处理完的时候,后面的人都要等着. 2 http1.0的队首阻塞 对于同一个tcp连接,所有的http1.0请求放入队列中,只有前一个请求的响应收到了,然后才能 ...
- Mongo.setReadPref(mode, tagSet) primaries and secondaries are treated equivalently. 读优先级策略
https://docs.mongodb.com/manual/reference/method/Mongo.setReadPref/#Mongo.setReadPref Mongo.setReadP ...
- 增加实时性的异常url检测
技能点: 搭建服务器.restfulapi 在py脚本中调取另一个脚本执行