Conventions - Writing Idiomatic Python (2013)

Writing Idiomatic Python (2013)

3. Conventions

This book adopts a number of conventions for convenience and readability purposes. Two in particular bear mentioning explicitly to clear up any confusion:

· print() is used as a function in both editions of the book. In the 2.7+ edition, there is an idiom devoted to using print in this way through the statement from __future__ import print_function. In all other code samples, this import statement is omitted for brevity.

· In some code samples, PEP-8 and/or PEP-257 are violated to accomodate formatting limitations or for brevity. In particular, most functions in code samples do not contain docstrings. Here again, the book has an explicit idiom regarding the consistent use of docstrings; they are ommitted for brevity. This may change in future versions

· All code samples, if they were part of a stand-alone script, would include an if __name__ == '__main__' statement and a main() function, as described by the idioms “Use the if __name__ == '__main__' pattern to allow a file to be both imported and run directly” and “Use sys.exitin your script to return proper error codes”. These statements are ommitted in code samples for brevity.