By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy. Some classes are designed to be inherited from, either to extend or modify aspects of the class’s behavior.
startswith() and endswith() are cleaner and less error prone. The formatter uses PEP 257 as a guide. I can find questions where people ask how to format docstrings and are referred to PEP 257 (e.g., this). The trim algorithm is implemented in inspect.cleandoc, of all places. This document and PEP 257 (Docstring Conventions) were adapted from Guido’s original Python Style Guide essay, with some additions from Barry’s style guide 2. Copied to clipboard.
I also see some info about tools that try to ensure your docstrings follow PEP 257 (e.g., this).
For flowing long blocks of text with fewer structural restrictions (docstrings or comments), the line length should be limited to 72 characters.
Identifiers used in the standard library must be ASCII compatible as described in the policy section of PEP 3131. Note 1: Properties only work on new-style classes.
There are a lot of different naming styles. What I can't find is any Python library that actually is a "docstring processing tool" that handles docstrings in the way defined in PEP 257 --- or at least, I can't find a tool that makes this docstring processing functionality directly available.
PEP 207 indicates that reflexivity rules are assumed by Python. In performance sensitive parts of the library, the ''.join() form should be used instead. While sometimes it’s okay to put an if/for/while with a small body on the same line, never do this for multi-clause statements.
Imports should usually be on separate lines, e.g. Authors whose names are not based on the latin alphabet MUST provide a latin transliteration of their names. For simple public data attributes, it is best to expose just the attribute name, without complicated accessor/mutator methods. Of course business is off, Pops, you're losing ground!
Comments that contradict the code are worse than no comments. Pep #257 (September 1971) Archie, 1960 Series < Previous Issue | | Next Issue > Price 0.15 USD Pages 36 Indicia Frequency monthly Publisher's Age Guidelines Approved by the Comics Code Authority Indicia / Colophon Publisher Archie Comic Publications, Inc. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. For example: The latter example doesn’t provide any information to indicate that the __enter__ and __exit__ methods are doing something other than closing the connection after a transaction. However it does not make sense to have a trailing comma on the same line as the closing delimiter (except in the above case of singleton tuples). Blank lines should be removed from the beginning and end of the docstring. Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. Any indentation in the first line of the docstring (i.e., up to the first newline) is insignificant and removed. The latter form is not legal Python 3 syntax.
Underscores can be used in the module name if it improves readability. Some web based tools may not offer dynamic line wrapping at all. Code should be written in a way that does not disadvantage other implementations of Python (PyPy, Jython, IronPython, Cython, Psyco, and such).