📄 222.html
字号:
<A Name="idx1073749585"></a>
<A NAMe="idx1073749586"></a>
<a nAME="idx1073749587"></A>
<a namE="idx1073749588"></A>
<A Name="idx1073749589"></a>
<a name="idx1073749590"></a>
</p>
<p>When creating <a name="idx1073749591"></a>modules, give them MixedCase or lowercase names. Use the first option whenever the module exports a single class or a bunch of related classes, and the second option when the module exports a group of functions. Also, note that module names are mapped to filenames in Python. Therefore, it is a good idea to pay special attention when giving a name to a module in order to avoid long names (module names can become truncated on some systems), and keep in mind that Python is case sensitive, which makes a module called <tt ClaSs="monofont">MyModule.py</tt> different from a module called <Tt claSs="monofont">mymodule.py.</tt> If you have two modules where one is a low-level interface written in C/C++, and the other one is a high-level object-oriented interface written in Python, the almost common standard nowadays is to give the Python's module a CapWords name (it isn't quite as widely used). On the other hand, the C/C++ module should be written entirely using lowercase letters, and preceded by a leading underscore (this is pretty much standardized). A known example of this concept is the pair of modules <TT CLass="monofont">Tkinter</tT> and <TT Class="monofont">_tkinter</TT>.</P>
<P>When writing <a namE="idx1073749592"></A>class names, you can stick to the CapWords pattern. Although this is a convention used most of the time, you are encouraged to modify this rule when handling internal classes of modules that are not supposed to be exported. You have to precede these classes with leading underscores.</P>
<P>When working with <a name="idx1073749593"></a>exceptions, you have two options. Their names are usually written in lowercase letters when part of built-in modules, whereas the ones that are part of Python modules are usually written using CapitalizedWords. The main deciding factor for creating exception names is whether you expect people to normally use <tt class="monofont">from ... import *</tt> or <tt claSs="monofont">import ...</tT> in the module.</p>
<p>When naming <a Name="idx1073749594"></a>functions, you are encouraged to use one from the next two style options: CapWords for functions that provide a large functionality (less used), and lowercase for functions that expose less useful classes.</P>
<p>When naming <a nAME="idx1073749595"></A>methods, you should stick to the CapWords style for methods that are published by an ILU interface. For all other cases, you should consider switching to lowercase. If you don't want a method to be visible by external methods or instances, you must put an underscore in front of it. As you can see in <a hreF="102.html">Chapter 5, "Object-Oriented Programming,"
</A> the use of this same concept can be applied to certain attributes in order to make them available only to their classes. Note that this last feature can be easily manipulated using the <TT clasS="monofont">__dict__</TT> attribute.</P>
<p>More details about these concepts can be found at</p>
<blOCKQuote>
<p>
<p>
<i> Python Style Guide,</i> by Guido Van Rossum</p>
<p><a target="_blank" hreF="http://www.python.org/doc/essays/styleguide.html">http://www.python.org/doc/essays/styleguide.html</a>
<a Name="idx1073749596"></A>
<a namE="idx1073749597"></a>
<a nAME="idx1073749598"></A>
<a namE="idx1073749599"></A>
<A Name="idx1073749600"></a>
<A NAMe="idx1073749601"></a>
<a nAME="idx1073749602"></A>
<a name="idx1073749603"></a>
<a name="idx1073749604"></a>
<a name="idx1073749605"></a>
<a nAme="idx1073749606"></A>
<a naMe="idx1073749607"></a>
</p>
</p>
</BlocKQUOte>
</foNT>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 1/30/2002<br>Python Developer's Handbook, © 2002 Sams Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="221.html" title="Building Python Applications"><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=222" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="222.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="223.html" title="Integrated Development Environments"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
</TD></TR></TABLE>
<br><TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD><H4 class=Title>Index terms contained in this section</H4>
<font size=2>
<a href="#idx1073749518"># (pound sign)</a><BR>
<a href="#idx1073749516">= (equal sign)</a><BR>
<a href="#idx1073749429">[nd]O command-line option</a><BR>
adding<BR>
<a href="#idx1073749535">comments to code</a> <a href="#idx1073749561">2nd</a><BR>
applications<BR>
<a href="#idx1073749442">optimizing performance</a> <a href="#idx1073749462">2nd</a> <a href="#idx1073749496">3rd</a><BR>
Python<BR>
<a href="#idx1073749410">building</a> <a href="#idx1073749422">2nd</a> <a href="#idx1073749433">3rd</a> <a href="#idx1073749452">4th</a> <a href="#idx1073749504">5th</a> <a href="#idx1073749525">6th</a> <a href="#idx1073749551">7th</a> <a href="#idx1073749568">8th</a> <a href="#idx1073749582">9th</a> <a href="#idx1073749599">10th</a><BR>
blocks<BR>
<a href="#idx1073749514">indented</a><BR>
building<BR>
<a href="#idx1073749409">Python applications</a> <a href="#idx1073749421">2nd</a> <a href="#idx1073749432">3rd</a> <a href="#idx1073749451">4th</a> <a href="#idx1073749503">5th</a> <a href="#idx1073749524">6th</a> <a href="#idx1073749550">7th</a> <a href="#idx1073749567">8th</a> <a href="#idx1073749581">9th</a> <a href="#idx1073749598">10th</a><BR>
classes<BR>
<a href="#idx1073749546">documentation strings</a><BR>
<a href="#idx1073749592">naming styles and conventions</a><BR>
code<BR>
<a href="#idx1073749439">optimizing</a> <a href="#idx1073749458">2nd</a> <a href="#idx1073749493">3rd</a><BR>
<a href="#idx1073749512">style guides</a> <a href="#idx1073749533">2nd</a> <a href="#idx1073749559">3rd</a> <a href="#idx1073749576">4th</a> <a href="#idx1073749590">5th</a> <a href="#idx1073749607">6th</a><BR>
command-line options<BR>
<a href="#idx1073749428">[nd]O</a><BR>
command-line scripts<BR>
<a href="#idx1073749417">testing</a><BR>
comments<BR>
<a href="#idx1073749534">adding to code</a> <a href="#idx1073749560">2nd</a><BR>
<a href="#idx1073749521">inline</a><BR>
construction methods<BR>
<a href="#idx1073749474">nested loops</a><BR>
creating<BR>
code<BR>
<a href="#idx1073749440">optimizing</a> <a href="#idx1073749459">2nd</a> <a href="#idx1073749494">3rd</a><BR>
<a href="#idx1073749511">style guides</a> <a href="#idx1073749532">2nd</a> <a href="#idx1073749558">3rd</a> <a href="#idx1073749575">4th</a> <a href="#idx1073749589">5th</a> <a href="#idx1073749606">6th</a><BR>
<a href="#idx1073749536">comments for code</a> <a href="#idx1073749562">2nd</a><BR>
<a href="#idx1073749413">Python applications</a> <a href="#idx1073749425">2nd</a> <a href="#idx1073749436">3rd</a> <a href="#idx1073749455">4th</a> <a href="#idx1073749507">5th</a> <a href="#idx1073749528">6th</a> <a href="#idx1073749554">7th</a> <a href="#idx1073749571">8th</a> <a href="#idx1073749585">9th</a> <a href="#idx1073749602">10th</a><BR>
development environments<BR>
<a href="#idx1073749407">building Python applications</a> <a href="#idx1073749419">2nd</a> <a href="#idx1073749430">3rd</a> <a href="#idx1073749449">4th</a> <a href="#idx1073749501">5th</a> <a href="#idx1073749522">6th</a> <a href="#idx1073749548">7th</a> <a href="#idx1073749565">8th</a> <a href="#idx1073749579">9th</a> <a href="#idx1073749596">10th</a><BR>
<a href="#idx1073749537">documentation strings</a> <a href="#idx1073749541">2nd</a> <a href="#idx1073749563">3rd</a><BR>
environments<BR>
development<BR>
<a href="#idx1073749408">building Python applications</a> <a href="#idx1073749420">2nd</a> <a href="#idx1073749431">3rd</a> <a href="#idx1073749450">4th</a> <a href="#idx1073749502">5th</a> <a href="#idx1073749523">6th</a> <a href="#idx1073749549">7th</a> <a href="#idx1073749566">8th</a> <a href="#idx1073749580">9th</a> <a href="#idx1073749597">10th</a><BR>
<a href="#idx1073749517">equal (=) sign</a><BR>
exceptions<BR>
<a href="#idx1073749593">naming styles and conventions</a><BR>
<a href="#idx1073749481">filter() function</a><BR>
functions<BR>
<a href="#idx1073749544">documentation strings</a><BR>
<a href="#idx1073749480">filter()</a><BR>
<a href="#idx1073749470">mainloop()</a><BR>
<a href="#idx1073749478">map()</a><BR>
<a href="#idx1073749594">naming styles and conventions</a><BR>
<a href="#idx1073749477">optimizing</a> <a href="#idx1073749484">2nd</a><BR>
<a href="#idx1073749482">reduce()</a><BR>
<a href="#idx1073749485">time()</a><BR>
<a href="#idx1073749490">time.clock()</a><BR>
importing<BR>
<a href="#idx1073749466">modules</a><BR>
<a href="#idx1073749487">time module</a><BR>
<a href="#idx1073749513">indented blocks</a><BR>
<a href="#idx1073749520">inline comments</a><BR>
loops<BR>
nested<BR>
<a href="#idx1073749476">construction methods</a><BR>
<a href="#idx1073749472">optimizing</a><BR>
<a href="#idx1073749471">mainloop() function</a><BR>
<a href="#idx1073749479">map() function</a><BR>
methods<BR>
construction<BR>
<a href="#idx1073749475">nested loops</a><BR>
<a href="#idx1073749545">documentation strings</a><BR>
<a href="#idx1073749595">naming styles and conventions</a><BR>
modules<BR>
<a href="#idx1073749543">documentation strings</a><BR>
<a href="#idx1073749591">naming styles and conventions</a><BR>
<a href="#idx1073749448">optimizing</a> <a href="#idx1073749461">2nd</a> <a href="#idx1073749467">3rd</a><BR>
time<BR>
<a href="#idx1073749489">importing</a><BR>
nested loops<BR>
<a href="#idx1073749473">construction methods</a><BR>
objects<BR>
<a href="#idx1073749577">naming styles and conventions</a> <a href="#idx1073749578">2nd</a><BR>
optimizing<BR>
<a href="#idx1073749438">code</a> <a href="#idx1073749457">2nd</a> <a href="#idx1073749492">3rd</a><BR>
options<BR>
command-line<BR>
<a href="#idx1073749427">[nd]O</a><BR>
performance<BR>
<a href="#idx1073749445">applications, optimizing</a> <a href="#idx1073749465">2nd</a> <a href="#idx1073749499">3rd</a><BR>
<a href="#idx1073749519">pound (#) sign</a><BR>
programs<BR>
<a href="#idx1073749443">optimizing performance</a> <a href="#idx1073749463">2nd</a> <a href="#idx1073749497">3rd</a><BR>
Python<BR>
<a href="#idx1073749411">building</a> <a href="#idx1073749423">2nd</a> <a href="#idx1073749434">3rd</a> <a href="#idx1073749453">4th</a> <a href="#idx1073749505">5th</a> <a href="#idx1073749526">6th</a> <a href="#idx1073749552">7th</a> <a href="#idx1073749569">8th</a> <a href="#idx1073749583">9th</a> <a href="#idx1073749600">10th</a><BR>
<a href="#idx1073749415">protyping</a><BR>
quotes<BR>
triple<BR>
<a href="#idx1073749540">documentation strings</a><BR>
<a href="#idx1073749483">reduce() function</a><BR>
<a href="#idx1073749500">Rossum, Guido van</a><BR>
scripts<BR>
command-line<BR>
<a href="#idx1073749418">testing</a><BR>
software<BR>
<a href="#idx1073749444">optimizing performance</a> <a href="#idx1073749464">2nd</a> <a href="#idx1073749498">3rd</a><BR>
Python<BR>
<a href="#idx1073749412">building</a> <a href="#idx1073749424">2nd</a> <a href="#idx1073749435">3rd</a> <a href="#idx1073749454">4th</a> <a href="#idx1073749506">5th</a> <a href="#idx1073749527">6th</a> <a href="#idx1073749553">7th</a> <a href="#idx1073749570">8th</a> <a href="#idx1073749584">9th</a> <a href="#idx1073749601">10th</a><BR>
strings<BR>
<a href="#idx1073749538">documentation</a> <a href="#idx1073749542">2nd</a> <a href="#idx1073749564">3rd</a><BR>
<a href="#idx1073749468">optimizing</a><BR>
style guides<BR>
<a href="#idx1073749509">writing code</a> <a href="#idx1073749530">2nd</a> <a href="#idx1073749556">3rd</a> <a href="#idx1073749573">4th</a> <a href="#idx1073749587">5th</a> <a href="#idx1073749604">6th</a><BR>
superclasses<BR>
<a href="#idx1073749547">documentation strings</a><BR>
testing<BR>
<a href="#idx1073749416">command-line scripts</a><BR>
time module<BR>
<a href="#idx1073749488">importing</a><BR>
<a href="#idx1073749486">time() function</a><BR>
<a href="#idx1073749491">time.clock() function</a><BR>
Tkinter<BR>
<a href="#idx1073749469">optimizing</a><BR>
triple quotes<BR>
<a href="#idx1073749539">documentation strings</a><BR>
variables<BR>
<a href="#idx1073749446">optimizing</a> <a href="#idx1073749447">2nd</a><BR>
<a href="#idx1073749515">whitespace</a><BR>
writing<BR>
code<BR>
<a href="#idx1073749441">optimizing</a> <a href="#idx1073749460">2nd</a> <a href="#idx1073749495">3rd</a><BR>
<a href="#idx1073749510">style guides</a> <a href="#idx1073749531">2nd</a> <a href="#idx1073749557">3rd</a> <a href="#idx1073749574">4th</a> <a href="#idx1073749588">5th</a> <a href="#idx1073749605">6th</a><BR>
<a href="#idx1073749414">Python applications</a> <a href="#idx1073749426">2nd</a> <a href="#idx1073749437">3rd</a> <a href="#idx1073749456">4th</a> <a href="#idx1073749508">5th</a> <a href="#idx1073749529">6th</a> <a href="#idx1073749555">7th</a> <a href="#idx1073749572">8th</a> <a href="#idx1073749586">9th</a> <a href="#idx1073749603">10th</a><BR>
<BR>
</font></TD></TR></TABLE>
<!--EndOfBrowse-->
</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -