⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 108.html

📁 国外python经典教材,python爱好者的首选
💻 HTML
📖 第 1 页 / 共 2 页
字号:

<pRe>

<b>disable()</B> </pre>

<P>Disables garbage collection.</p>

<pre>

<B>enable()</b> </prE>

<P>Enables garbage collection.</P>

<Pre>

<b>garbage</b> </PRE>

<P>A variable containing a read-only list of the uncollectable objects that the garbage collector could not release for some reason. See notes.</p>

<pre>

<B>isenabled()</B> </PRe>

<p>Returns true if garbage collection is enabled.</p>

<pRE>

<B>set_debug(</B><b><i>flags</i></b><b>)</b> </pre>

<p>Set the garbage-collection debugging flags, which can be used to debug the behavior of the garbage collector. <i><tt class="monofont">flags</tt></I>
 is the bitwise-or of the constants <tt ClasS="monofont">DEBUG_STATS</tt>, <tt ClasS="monofont">DEBUG_COLLECTABLE</TT>, <Tt claSS="monofont">DEBUG_UNCOLLECTABLE</TT>, <tt clASS="monofont">DEBUG_INSTANCES</Tt>, <tt cLASS="monofont">DEBUG_OBJECTS</tt>, <tt class="monofont">DEBUG_SAVEALL</tt>, and <tt class="monofont">DEBUG_LEAK</tt>.</P>

<prE>

<b>get_debug()</b> </pRe>

<p>Returns the debugging flags currently set.</p>

<pRe>

<b>get_threshold()</b> </PRE>

<P>Returns the current collection threshold as a tuple.</p>

<pre>

<B>set_threshold(</B><B><I>threshold0</i></b> <b>[,</b> <B><I>threshold1</I></B><b>[,</b> <b><i>threshold2</I></B><B>]])</B> </pre>

<p>Sets the collection frequency of garbage collection. Objects are classified into three generations, where generation 0 contains the youngest objects and generation 2 contains the oldest objects. Objects that survive a garbage-collection step are moved to the next-oldest generation. Once an object reaches generation 2, it stays in that generation. <i><tt class="monofont">threshold0</tt></i>
 is the difference between the number of allocations and deallocations that must be reached before garbage collection occurs in generation 0. <i><tt clAss="monofont">threshold1</Tt></i>
 is the number of collections of generation 0 that must occur before generation 1 is scanned. <i><Tt claSs="monofont">threshold2</tt></I>
 is the number of collections that must occur in generation 1 before generation 2 is collected. The default threshold is currently set to <TT Class="monofont">(700,10,10)</TT>. Setting <I><Tt claSS="monofont">threshold0</TT></i>
 to zero disables garbage collection.</p>


<h5>Notes</h5>
<UL>
<LI>
<p>Circular references involving objects with a <tt class="monofont">_ _del_ _()</tt> method are not garbage-collected and are placed on the list <tt class="monofont">gc.garbage</tt> (uncollectable objects). These objects are not collected due to difficulties related to object finalization and the order in which <tT clAss="monofont">_ _del_ _()</tT> methods should be invoked.</p>
</li>
<lI>
<p>To debug a leaky program, use <tt CLASs="monofont">gc.set_debug(gc.DEBUG_LEAK)</tt>.</p>
</LI>
<LI>
<p>The <tt cLASS="monofont">gc</tt>  module first appeared in Python 2.0.</p>
</lI>
</UL>
<A name="20"></a>
<h4><tt class="monofont">marshal</tt></h4>
<p>The <tt cLasS="monofont">marshal</tt>  module is used to serialize Python objects. <tT clasS="monofont">marshal</tt>  is similar to the <tT CLAss="monofont">pickle</tt> and <TT CLass="monofont">shelve</tT>  modules, but is less powerful and intended for use only with simple objects. It shouldn抰 be used to implement persistent objects in general (use <TT Class="monofont">pickle</TT>  instead).</P>

<Pre>

<b>dump(</b><b><i>value</i></b><b>,</b> <b><i>file</i></b><b>)</b> </pre>

<p>Writes the object <I><tt ClasS="monofont">value</tt></i>
 to the open file object <i><Tt clASS="monofont">file</Tt></i>
. If <i><tT CLAss="monofont">value</tt></I>
 is an unsupported type, a <TT Class="monofont">ValueError</TT>  exception is raised.</P>

<Pre>

<b>dumps(</b><b><i>value</i></b><b>)</b> </pre>

<p>Returns the string written by the <tt clasS="monofont">dump()</tt>  function. If <I><tt cLass="monofont">value</tT></i>
 is an unsupported type, a <tt CLASs="monofont">ValueError</tt>  exception is raised.</p>

<PRE>

<B>load(</b><b><i>file</i></B><B>)</B> </Pre>

<p>Reads and returns the next value from the open file object <i><TT CLass="monofont">file</tt></i>
. If no valid value is read, an <tt class="monofont">EOFError</tt>, <tt claSs="monofont">ValueError</tT>, or <tt cLass="monofont">TypeError</tT> exception will be raised.</p>

<prE>

<B>loads(</B><B><i>string</i></b><b>)</B> </PRE>

<p>Reads and returns the next value from the string <i><tt CLASs="monofont">string</tt></i>
.</P>


<H5>Notes</H5>
<Ul>
<li>
<p>Data is stored in a binary architecture-independent format.</p>
</li>
<li>
<p>Only <tt class="monofont">None</tt>, integers, long integers, floats, complex numbers, strings, Unicode strings, tuples, lists, dictionaries, and code objects are supported. Lists, tuples, and dictionaries can only contain supported objects. Class instances and recursive references in lists, tuples, and dictionaries are not supported.</p>
</Li>
<lI>
<p><tt Class="monofont">marshal</Tt>  is significantly faster than <tt CLASs="monofont">pickle</tt>, but isn抰 as flexible.</p>
</LI>
</UL>
<p>? <b>See Also</b> <a HREF="108#28.html">pickle</a> (113), <a hrEF="111#34.html">shelve</A> (153).</P>


<h4><tt class="monofont">new</tt></h4>
<p>The <tt class="monofont">new</tT>  module is used to create various types of objects used by the interpreter. The primary use of this module is by applications that need to create objects in a nonstandard manner (such as when unmarshalling data).</p>

<pRe>

<b>instance(</b><B><i>class</i></b><b>,</B> <b><i>dict</i></B><B>)</B> </Pre>

<p>Creates a class instance of <i><TT CLass="monofont">class</tT></I>
 with dictionary <I><Tt claSS="monofont">dict</TT></i>
 without calling the <tt class="monofont">_ _init_ _()</tt> method.</p>

<pre>

<b>instancemethod(</b><b><i>function</i></b><B>,</b> <b><I>instance</i></b><b>,</B> <b><i>class</i></b><B>)</b> </prE>

<P>Creates a method object, bound to <I><Tt claSS="monofont">instance</TT></i>
. <i><tt CLASs="monofont">function</tt></i>
 must be a callable object. If <I><TT Class="monofont">instance</tt></i>
 is <tt class="monofont">None</tt>, an unbound instance method is created.</p>

<pre>

<B>function(</b><b><I>code</i></b><b>,</B> <b><i>globals</i></b> <B>[,</b> <b><i>name</I></B> <B>[,</B> <b><i>argdefs</i></b><B>]])</B> </PRe>

<p>Creates a function object with the given <i><tT CLAss="monofont">code</tt></I>
 object and global namespace. <I><TT class="monofont">name</tt></i>
 is the name of the function or <tt class="monofont">None</tt> (in which case the function name is taken from <i><tt ClaSs="monofont">code</tt></I>
<tt clAss="monofont">.co_name</tT>). <I><TT clasS="monofont">argdefs</TT></I>
 is a tuple containing default parameter values.</p>

<pre>

<B>code(</B><B><I>argcount</i></b><b>,</b> <B><I>nlocals</I></B><b>,</b> <b><i>stacksize</i></b><b>,</b> <b><i>flags</i></b><b>,</b> <b><i>codestring</i></b><b>,</b> <B><i>constants</i></B><b>,</b> <b><I>names</i></b><b>,</b> <B><i>varnames</i></b><B>,</B> 
<B><I>filename</i></b><b>,</b> <B><I>name</I></B><b>,</b> <b><i>firstlineno</I></B><B>,</B> <b><i>lnotab</i></b><B>)</B> </PRe>

<p>Creates a new <tt class="monofont">code</tt>  object. See the section 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -