Changeset 244

Show
Ignore:
Timestamp:
Thu Dec 8 22:38:17 2005
Author:
limodou
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
  • zh-translations/branches/diveintopython-zh-5.4/zh-cn/xml/fileinfo.xml

    r240 r244  
    200 200 <abstract>  
    201 201 <title/>  
    202   <para>&python; is fully object-oriented: you can define your own classes, inherit from your own or built-in classes, and instantiate the classes you've defined.</para>  
      202 <para>&python; 是完全面向对象的:你可以定义自已的类,从自已的或内置的类继承,然后从你定义的类创建实例。</para>  
    202 202 </abstract>  
    203   <para>Defining a class in &python; is simple.  As with functions, there is no separate interface definition.  Just define the class and start coding.  A &python; class starts with the reserved word &class;, followed by the class name.  Technically, that's all that's required, since a class doesn't need to inherit from any other class.</para>  
      203 <para>在 &python; 中定义类很简单。就象定义函数,没有单独的接口定义。只要定义类,然后就可以开始编码。&python; 类开始为保留字 &class;,后面跟着类名。从技术上讲,有这些就够了,因为一个类并不必须从其它类继承。</para>  
    203 203 <example id="fileinfo.class.simplest">  
    204   <title>The Simplest &python; Class</title>  
      204 <title>最简单的 &python; 类</title>  
    204 204 <programlisting>  
    205 205 class Loaf: <co id="fileinfo.class.1.1"/>  
     
    210 210 <calloutlist>  
    211 211 <callout arearefs="fileinfo.class.1.1">  
    212   <para>The name of this class is <classname>Loaf</classname>, and it doesn't inherit from any other class.  Class names are usually capitalized, <classname>EachWordLikeThis</classname>, but this is only a convention, not a requirement.</para>  
      212 <para>这个类的名字是 <classname>Loaf</classname>,它没有从其它类继承。 类名通常是第一个字母大写,如:<classname>EachWordLikeThis</classname>,但这只是一个习惯,不是一个必要条件。</para>  
    212 212 </callout>  
    213 213 <callout arearefs="fileinfo.class.1.2">  
    214   <para>This class doesn't define any methods or attributes, but syntactically, there needs to be something in the definition, so you use &pass;.  This is a &python; reserved word that just means <quote>move along, nothing to see here</quote>.  It's a statement that does nothing, and it's a good placeholder when you're stubbing out functions or classes.</para>  
      214 <para>这个类没有定义任何方法或属性,但是从语法上,需要在定义中有些东西,所以你使用 &pass;。这是一个&python;保留字,仅仅表示<quote>向前走,不要往这看</quote>。它是一条什么都不做的语句,当你删空函数或类时,它是一个很好的占位符。</para>  
    214 214 </callout>  
    215 215 <callout arearefs="fileinfo.class.1.3">  
    216   <para>You probably guessed this, but everything in a class is indented, just like the code within a function, &if; statement, &for; loop, and so forth.  The first thing not indented is not in the class.</para>  
      216 <para>你可能猜到了,在类中的所有东西都要缩近,就象位于函数、&if; 语句,&for; 循环,诸如些类的代码。第一条不缩近的东西不属于这个类。</para>  
    216 216 </callout>  
    217 217 </calloutlist>  
    222 222 <note id="compare.pass.java" role="compare" vendor="java">  
    223 223 <title>&python; &vs; &java;: &pass;</title>  
    224   <para>The &pass; statement in &python; is like an empty set of braces (<literal>{}</literal>) in &java; or &c;.</para>  
      224 <para>在 &python; 中的 &pass; 语句就象 &java; 或 &c; 中的大括号空集(<literal>{}</literal>)。</para>  
    224 224 </note>  
    225 225 <para>Of course, realistically, most classes will be inherited from other classes, and they will define their own class methods and attributes.  But as you've just seen, there is nothing that a class absolutely must have, other than a name.  In particular, &cpp; programmers may find it odd that &python; classes don't have explicit constructors and destructors.  &python; classes do have something similar to a constructor: the &init; method.</para>