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()

转载于:https://www.cnblogs.com/AnXiaoXi/archive/2012/11/26/2789427.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值