Annotations specification in Python

Source: Internet
Author: User

In Python, there are single-line comments, multiline comments, special annotations

Special NOTES:

#!/usr/bin/env python

This annotation means: Python tells Linux which path to search for Python's translator

#-*-coding:utf-8-*-

This annotation means: Tell the Python interpreter how to interpret the encoding type in the string

Multi-line Comment:/**/

Typically used to annotate class documents, function documents

Single-line Comment: #

Comment Requirements:

Function and Method Comments:

Args; Lists the name of each parameter and uses a colon and a space after the name to separate the description of the parameter. If the description is too long than a single line of 80 characters, hang indents with 2 or 4 spaces (consistent with other parts of the file). The description should include the desired type and meaning. If a function accepts *foo (variable-length argument list) or **bar (any keyword argument), the *foo and **bar should be listed in detail.

Returns: (or yields: for generators) describes the type and semantics of the return value. If the function returns none, this part can be omitted.

Raises: Lists all exceptions related to the interface.

EXAMPLE:

      

DefFetch_bigtable_rows(Big_table,Keys,Other_silly_variable=None):"" "fetches rows from a Bigtable.Retrieves rows pertaining to the given keys from the Table instancerepresented by Big_table. Silly things may happen ifOther_silly_variable is not None.Args:Big_table:an Open Bigtable Table instance.Keys:a sequence of strings representing the key of each table rowto fetch. other_silly_variable:another Optional variable, that have a much longer name than the other args, and which does Nothing. 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 ')} If a key from the keys argument are missing from the dictionary and then so row was not found in the t Able. raises: Ioerror:an error occurred accessing the bigtable. Table object. "" "  Pass

Comments for Class

The class should have a document string that describes the class under its definition. If your class has public properties (Attributes), then there should be an attribute (Attributes) segment in the document. And you should follow the same format as the function parameter.

    

ClassSampleClass(Object):"" "Summary of class here.Longer class information ....Longer class information ....Attributes: Likes_spam:a Boolean indicating if we like spam or not.  Eggs:an integer count of the eggs we have laid.  "" "def __init__ (self likes_spam=false): self. Likes_spam = likes_spam self. Eggs = 0 def public_method (self "" "performs operation blah." "" 

/span>

Annotation specifications in Python

Related Article

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.