python0.0.0.4

 

Attribute Description
__bases__   A tuple that contains base classes from which the class directly inherits.
If the class does not inherit from other classes, the tuple is empty.
[Note: We discuss base classes and inheritance in Chapter 9, Object-
Oriented Programming: Inheritance.]
__dict__     A dictionary that corresponds to the class’s namespace. Each keyvalue
pair represents an identifier and its value in the namespace.
__doc__    A class’s docstring. If the class does not specify a docstring, the value
is None.
__module__  A string that contains the module (file) name in which the class is
defined.
__name__   A string that contains the class’s name.

 

 

代码
 
   
1 # Fig. 7.1: Time1.py
2 # Simple definition of class Time.
3  
4   class Time:
5 """ Time abstract data type (ADT) definition """
6
7 def __init__ ( self ):
8 """ Initializes hour, minute and second to zero """
9
10 self.hour = 0 # 0-23
11   self.minute = 0 # 0-59
12   self.second = 0 # 0-59
13  
14 def printMilitary( self ):
15 """ Prints object of class Time in military format """
16
17 print " %.2d:%.2d:%.2d " % ( self.hour, self.minute, self.second )
18
19 def printStandard( self ):
20 """ Prints object of class Time in standard format """
21
22 standardTime = ""
23
24 if self.hour == 0 or self.hour == 12 :
25 standardTime += " 12: "
26 else :
27 standardTime += " %d: " % ( self.hour % 12 )
28
29 standardTime += " %.2d:%.2d " % ( self.minute, self.second )
30
31 if self.hour < 12 :
32 standardTime += " AM "
33 else :
34 standardTime += " PM "
35
36 print standardTime,
37
38   # #########################################################################
39 # (C) Copyright 2002 by Deitel & Associates, Inc. and Prentice Hall. #
40 # All Rights Reserved. #
41 # #
42 # DISCLAIMER: The authors and publisher of this book have used their #
43 # best efforts in preparing the book. These efforts include the #
44 # development, research, and testing of the theories and programs #
45 # to determine their effectiveness. The authors and publisher make #
46 # no warranty of any kind, expressed or implied, with regard to these #
47 # programs or to the documentation contained in these books. The authors #
48 # and publisher shall not be liable in any event for incidental or #
49 # consequential damages in connection with, or arising out of, the #
50 # furnishing, performance, or use of these programs. #
51 # #########################################################################
52  

 

>>> from Time1 import Time //Time1是文件名 Time是类名

>>> print Time.__bases__
()
>>> print Time.__dict__
{'printMilitary': <function printMilitary at 0x018DF9F0>, '__module__': 'Time1', '__doc__': 'Time abstract data type (AD
T) definition', '__init__': <function __init__ at 0x018DF9B0>, 'printStandard': <function printStandard at 0x018DFA30>}
>>> print Time.__module__
Time1
>>> print Time.__name__
Time
>>>

 

 

 

 

 

转载于:https://www.cnblogs.com/caidaodaxia/archive/2010/08/24/1807214.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值