標籤:img statistic uil size install wave erer table pil
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():passp = 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 kwlistprint(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 zipimportabc html secrets zlibactivate_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的繼承體系