""" # 模块文档(文档字符串是包, 模块, 类或函数里的第一个三引号包围语句,会被__doc__变量自动读取) desc: this is modle doc """ # - (int) timeout: # The timeout which is the maximum time a remote client may spend # between FTP commands. If the timeout triggers, the remote client # will be kicked off. Defaults to 300 seconds. timeout = 120 import sys.modules # 先引入系统模块 # 空一行 import third.part.modules # 第三方模块 # 空一行 import self.packages # 自己的模块 class Parent(object): # 类明首字母大写,并继承object """ # 类文档,该变量不能被继承 this is class Parent doc """ __slots__ = ( # 定义类中所有可能出现的变量,如果创建新的变量则会报错,作用于__dict__类似,但比__dict__更严格 'fang', 'qiang', ) def __init__(self, value):# 这个函数中初始化所有变量 """ desc # 函数文档(秒速函数做什么, 以及输入和输出的详细描述) detail Args: value: value to init Returns: A dict mapping keys to the corresponding table row data fetched. Each row is represented as a tuple of strings. For example: {'Serak': ('Rigel VII', 'Preparer'), 'Zim': ('Irk', 'Invader'), 'Lrrr': ('Omicron Persei 8', 'Emperor')} Raises: IOError: An error occurred accessing the bigtable.Table object. """ self.fang = 'fang' # 操作符两边留一个空格,关键字参数除外 self.qiang = {'a':1} self.value=value print("Parent __init__ called") # leave la line between functions def show_value(self): # 函数命名 “ 动词_名词 ” print self.value class Son(Parent): def __init__(self, value, value1):# 参数分隔时逗号后加一个空格 self.value = value self.value1 = value1 print("Son __init__ called") def show_value(self): Parent.show_value(self) # 调用父类函数 super(Son,self).show_value() # 调用父类函数(适用于多继承时不知道某函数不知道来自哪个父类) print self.value,self.value1 @staticmethod # 静态函数,不需要self参数 def say_hello(): print "say hello" s=Son(1,2) s.show_value()