python模塊規定的格式

python模塊規定的格式,按照這樣寫,最規範。

一個python模塊代碼結構一般按照以下格式寫,請參照!

#1)起始行

#!/usr/bin/env python

# -*- codeing:utf-8 -*-

#2)模塊文檔
"""Show off features of [pydoc] module

This is a silly module to
demonstrate docstrings
"""

#3)模塊信息
__author__ = 'python' 
__version__= '1.0'
__nonsense__ = 'aaaabbbbccc'

 

 

#4)導入模塊

import sys

import os

#5)全局變量

 

debug=true

 

#6)類的定義

class MyClass(object): 
  """Demonstrate class docstrings"""
  def __init__ (self, spam=1, eggs=2):
      """Set default attribute values only
      Keyword arguments:
      spam ― a processed meat product
      eggs ― a fine breakfast for lumberjacks
      """
      self.spam = spam
      self.eggs = eggs
      if debug:
          print 'ran __init__(...)'

#7)函數定義

def test():

   "test function"

    myclass = MyClass()

if debug:
             print 'ran test(...)'

#8)主程序定義

     if __name__ == '__main__':

                test()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章