[py]python的继承体系
python的继承体系
python中一切皆对象

随着类的定义而开辟执行
class Foo(object):
print 'Loading...'
spam = 'eggs'
print 'Done!'
class MetaClass(type):
def __init__(cls, name, bases, attrs):
print('Defining %s' % cls)
print('Name: %s' % name)
print('Bases: %s' % (bases,))
print('Attributes:')
for (name, value) in attrs.items():
print(' %s: %r' % (name, value))
class RealClass(object, metaclass=MetaClass):
spam = 'eggs'
判断对象是否属于这个类
class person():pass
p = person()
isinstance(p2,person)
类的方法
__class__
__delattr__
__dict__
__dir__
__doc__
__eq__
__format__
__ge__
__getattribute__
__gt__
__hash__
__init__
__init_subclass__
__le__
__lt__
__module__
__ne__
__new__
__reduce__
__reduce_ex__
__repr__
__setattr__
__sizeof__
__str__
__subclasshook__
__weakref__
实例和类存储
静态字段
普通字段
普通方法
类方法
静态方法
字段:
普通字段
静态字段 共享内存
方法都共享内存: 只不过调用方法不同
普通方法 self
类方法 不需要self
静态方法 cls
关键字
from keyword import kwlist
print(kwlist)
>>> help()
help> keywords
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
查看本地环境所有可用模块
help('modules')
IPython aifc idlelib selectors
__future__ antigravity imaplib setuptools
__main__ argparse imghdr shelve
_ast array imp shlex
_asyncio ast importlib shutil
_bisect asynchat inspect signal
_blake2 asyncio io simplegener
_bootlocale asyncore ipaddress site
_bz2 atexit ipython_genutils six
_codecs audioop itertools smtpd
_codecs_cn autoreload jedi smtplib
_codecs_hk base64 jieba sndhdr
_codecs_iso2022 bdb json socket
_codecs_jp binascii keyword socketserve
_codecs_kr binhex lib2to3 sqlite3
_codecs_tw bisect linecache sre_compile
_collections builtins locale sre_constan
_collections_abc bz2 logging sre_parse
_compat_pickle cProfile lzma ssl
_compression calendar macpath stat
_csv cgi macurl2path statistics
_ctypes cgitb mailbox storemagic
_ctypes_test chunk mailcap string
_datetime cmath markdown stringprep
_decimal cmd marshal struct
_dummy_thread code math subprocess
_elementtree codecs mimetypes sunau
_findvs codeop mmap symbol
_functools collections modulefinder sympyprinti
_hashlib colorama msilib symtable
_heapq colorsys msvcrt sys
_imp compileall multiprocessing sysconfig
_io concurrent netrc tabnanny
_json configparser nntplib tarfile
_locale contextlib nt telnetlib
_lsprof copy ntpath tempfile
_lzma copyreg nturl2path test
_markupbase crypt numbers tests
_md5 csv opcode textwrap
_msi ctypes operator this
_multibytecodec curses optparse threading
_multiprocessing cythonmagic os time
_opcode datetime parser timeit
_operator dbm parso tkinter
_osx_support decimal pathlib token
_overlapped decorator pdb tokenize
_pickle difflib pickle trace
_pydecimal dis pickleshare traceback
_pyio distutils pickletools tracemalloc
_random django pip traitlets
_sha1 django-admin pipes tty
_sha256 doctest pkg_resources turtle
_sha3 dummy_threading pkgutil turtledemo
_sha512 easy_install platform types
_signal email plistlib typing
_sitebuiltins encodings poplib unicodedata
_socket ensurepip posixpath unittest
_sqlite3 enum pprint urllib
_sre errno profile uu
_ssl faulthandler prompt_toolkit uuid
_stat filecmp pstats venv
_string fileinput pty warnings
_strptime fnmatch py_compile wave
_struct formatter pyclbr wcwidth
_symtable fractions pydoc weakref
_testbuffer ftplib pydoc_data webbrowser
_testcapi functools pyexpat wheel
_testconsole gc pygments whoosh
_testimportmultiple genericpath pytz winreg
_testmultiphase getopt queue winsound
_thread getpass quopri wsgiref
_threading_local gettext random xdrlib
_tkinter glob re xml
_tracemalloc gzip reprlib xmlrpc
_warnings hashlib rlcompleter xxsubtype
_weakref haystack rmagic zipapp
_weakrefset heapq runpy zipfile
_winapi hmac sched zipimport
abc html secrets zlib
activate_this http select
dir() 函数: 显示模块属性和方法
__builtin__模块在Python3中重命名为builtins。
In [2]: dir(__builtins__)
Out[2]:
['ArithmeticError',
'AssertionError',
'AttributeError',
'BaseException',
'BlockingIOError',
'BrokenPipeError',
'BufferError',
'BytesWarning',
'ChildProcessError',
'ConnectionAbortedError',
'ConnectionError',
'ConnectionRefusedError',
'ConnectionResetError',
'DeprecationWarning',
'EOFError',
'Ellipsis',
'EnvironmentError',
'Exception',
'False',
'FileExistsError',
'FileNotFoundError',
'FloatingPointError',
'FutureWarning',
'GeneratorExit',
'IOError',
'ImportError',
'ImportWarning',
'IndentationError',
'IndexError',
'InterruptedError',
'IsADirectoryError',
'KeyError',
'KeyboardInterrupt',
'LookupError',
'MemoryError',
'ModuleNotFoundError',
'NameError',
'None',
'NotADirectoryError',
'NotImplemented',
'NotImplementedError',
'OSError',
'OverflowError',
'PendingDeprecationWarnin
'PermissionError',
'ProcessLookupError',
'RecursionError',
'ReferenceError',
'ResourceWarning',
'RuntimeError',
'RuntimeWarning',
'StopAsyncIteration',
'StopIteration',
'SyntaxError',
'SyntaxWarning',
'SystemError',
'SystemExit',
'TabError',
'TimeoutError',
'True',
'TypeError',
'UnboundLocalError',
'UnicodeDecodeError',
'UnicodeEncodeError',
'UnicodeError',
'UnicodeTranslateError',
'UnicodeWarning',
'UserWarning',
'ValueError',
'Warning',
'WindowsError',
'ZeroDivisionError',
'__IPYTHON__',
'__build_class__',
'__debug__',
'__doc__',
'__import__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'abs',
'all',
'any',
'ascii',
'bin',
'bool',
'bytearray',
'bytes',
'callable',
'chr',
'classmethod',
'compile',
'complex',
'copyright',
'credits',
'delattr',
'dict',
'dir',
'display',
'divmod',
'enumerate',
'eval',
'exec',
'filter',
'float',
'format',
'frozenset',
'get_ipython',
'getattr',
'globals',
'hasattr',
'hash',
'help',
'hex',
'id',
'input',
'int',
'isinstance',
'issubclass',
'iter',
'len',
'license',
'list',
'locals',
'map',
'max',
'memoryview',
'min',
'next',
'object',
'oct',
'open',
'ord',
'pow',
'print',
'property',
'range',
'repr',
'reversed',
'round',
'set',
'setattr',
'slice',
'sorted',
'staticmethod',
'str',
'sum',
'super',
'tuple',
'type',
'vars',
'zip']
模块的继承

有个疑问
[py]python的继承体系的更多相关文章
- [py]python的继承体系-源码目录结构
python3安装目录 pip install virtualenv pip install virtualenvwrapper pip install virtualenvwrapper-win m ...
- python基础——继承和多态
python基础——继承和多态 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类 ...
- [修]python普通继承方式和super继承方式
[转]python普通继承方式和super继承方式 原文出自:http://www.360doc.com/content/13/0306/15/9934052_269664772.shtml 原文的错 ...
- Python进阶-继承中的MRO与super
Python进阶-继承中的MRO与super 写在前面 如非特别说明,下文均基于Python3 摘要 本文讲述Python继承关系中如何通过super()调用"父类"方法,supe ...
- Python面向对象 -- 继承和多态、获取对象信息、实例属性和类属性
继承和多态 继承的好处: 1,子类可以使用父类的全部功能 2,多态:当子类和父类都存在相同的方法时,子类的方法会覆盖父类的方法,即调用时会调用子类的方法.这就是继承的另一个好处:多态. 多态: 调用方 ...
- Python面向对象-继承和多态特性
继承 在面向对象的程序设计中,当我们定义一个class时候,可以从现有的class继承,新的class成为子类,被继承的class称为基类,父类或超类. 比如,编写一个名为Animal的class: ...
- python 子类继承父类__init__(转载)
转载: http://www.jb51.net/article/100195.htm 前言 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__方法 ...
- 代码的坏味道(12)——平行继承体系(Parallel Inheritance Hierarchies)
坏味道--平行继承体系(Parallel Inheritance Hierarchies) 平行继承体系(Parallel Inheritance Hierarchies) 其实是 霰弹式修改(Sho ...
- 从基层容器类看万变不离其宗的JAVA继承体系
以容器类为例子,可以观一叶而知秋,看看以前的前辈们是如何处理各种面向对象思想下的继承体系的.读的源代码越多,就越要总结这个继承关系否则读的多也忘得快. 首先摆上一张图片: 看到这张图很多人就慌了,难道 ...
随机推荐
- Discuz常见大问题-如何使用云采集插件
在百度中搜discuz 云采集插件(直接在Discuz官方的插件库中搜可能搜不到) 启用这个插件 随后在任意版块发帖的时候,顶部都会有一个文本框,可以直接放别人博客的帖子,点击获取将生成到你发的帖子中 ...
- C#中相关结构的用法及用途
C#中Dictionary的用法及用途 http://www.cnblogs.com/linzheng/archive/2010/12/13/1904709.html C#中的Dictionary字典 ...
- Java多线程(1) 创建
一.线程的生命周期及五种基本状态 关于Java中线程的生命周期,首先看一下以下这张较为经典的图: Java线程具有五中基本状态 新建状态(New):当线程对象对创建后,即进入了新建状态,如:Threa ...
- vim插件之pathogen,NERDTree,Command-T,Powerline
pathogen 功能说明 一个插件包往往具备多种功能,每个文件根据Vim的路径约定会放置到不同的目录下,通用插件放到plugin下,语法高亮插件放到syntax下,自动加载插件放到autoload下 ...
- maven 创建web项目的标准目录结构
maven 创建web项目的标准目录结构 CreateTime--2018年4月18日21:05:37 Author:Marydon 1.标准目录介绍(开发目录) 2.在eclipse下,目录展示 ...
- 〖Linux〗联想K860/i Android 4.2及以上的Bootimg解压与打包工具
因为自己有需要,所以花了一点时间来写了一下. 1. 解压工具 #!/bin/bash - #====================================================== ...
- mysql-cluster 7.3.5-linux 安装
[集群环境] 管理节点 10.0.0.19 数据节点 10.0.0.12 10.0.0.17 sql节点 10.0.0.18 10.0.0 ...
- openssh入门
ssh (secure shell),ssh协议支持登录及文件的传输加密防止数据截留! 01.下载 https://www.ssh.com/ ...
- 使用SpringMVC搭建第一个项目
概述 使用SpringMVC搭建第一个项目,入门教程,分享给大家. 详细 代码下载:http://www.demodashi.com/demo/10596.html 一.概述 1.什么是Spring ...
- POJ 3468 A Simple Problem with Integers 【树状数组】
题目链接:id=3468">http://poj.org/problem?id=3468 题目大意:给出一组数组v[i],有两种操作,一种给出两个数a,b.要求输出v[a]到v[b]之 ...