The format specified by the python module is the most standard.

Source: Internet
Author: User

The format specified by the python module is the most standard.

The code structure of a python module is generally written in the following format. Refer!

#1) start line

#! /Usr/bin/env python

#-*-Codeing: UTF-8 -*-

#2) module documentation
"Show off features of [pydoc] module

This is a silly module
Demonstrate docstrings
"""

#3) module information
_ Author _ = 'python'
_ Version __= '1. 0'
_ Nonsense _ = 'aaaabbbbccc'

 

 

#4) import module

Import sys

Import OS

#5) global variables

 

Debug = true

 

#6) Class Definition

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) Function Definition

Def test ():

"Test function"

Myclass = MyClass ()

If debug:
Print 'ran test (...)'

#8) main program Definition

If _ name _ = '_ main __':

Test ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.