112.html
来自「Python Ebook Python&XML」· HTML 代码 · 共 32 行
HTML
32 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Developer's Handbook -> Metaclasses</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="8.html" class="navtitle">Web Development</a> > <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> > <a href="102.html" class="navtitle">5. Object-Oriented Programming</a> > <span class="nonavtitle">Metaclasses</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="111.html" title="Encapsulation"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0672319942&snode=112" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="112.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="113.html" title="Summary"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F31%2F2002+4%3A34%3A09+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039199167010047123209178152124239215162147032037055053230108169</font><a href="read3.asp?bookname=0672319942&snode=112&now=5%2F31%2F2002+4%3A34%3A09+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT><h3>Metaclasses</h3>
<p>A <i>metaclass</I> is just a class that is used as a template to create class-like entities.</P>
<P>Normally, you create instances based on classes. The goal here is to create classes (<A name="idx1073743507"></A><I>metainstances</I>) based on other classes (<I>metaclasses</i>). The resulting metainstances are used as base classes for your own classes.</p>
<p>The whole idea is to offer you the possibility of operating Python's internal class-handling engine. Everything that usually happens behind the scenes while manipulating your classes and objects now can be accessed and changed. The meta instance makes it easier for you to handle the task of modifying the attribute lookup behavior of objects.</p>
<P>Prior to Python, version 1.5, it was necessary to use C extensions in order to define metaclasses.</P>
<P>The subsequent code defines a simple metaclass and its supporting classes. Note that this structure doesn't cover the whole model.</P>
<pre>
1: >>> import types
2: >>> class METACLASS:
3:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?