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