pedantic-python.readme.io
Main() · Pedantic Python
https://pedantic-python.readme.io/docs/main
One statement per line. Your code should always check if ` name = ' main '` before executing your main program so that the main program is not executed when the module is imported. [block:code] { codes: [ { code: def main(): n pass n nif name = ' main ': n main(), language: python } ] } [/block].
pedantic-python.readme.io
Truth value testing · Pedantic Python
https://pedantic-python.readme.io/docs/truth-value-testing
N nif attr = None: n print 'attr is None! N n# Good n# Just check the value nif attr: n print 'attr is truthy! N n# or check for the opposite nif not attr: n print 'attr is falsey! N n# or, since None is considered false, explicitly check for it nif attr is None: n print 'attr is None! N language : python n } n ] n} n[/block],excerpt:,slug:truth-value-testing,type:basic,title:Truth value testing}. One statement per line. N nif attr = None: n print 'attr is None! Language: python } ] } [/block].
pedantic-python.readme.io
Comments · Pedantic Python
https://pedantic-python.readme.io/docs/comments
One statement per line. It is used to explain what the code does in plain English.
pedantic-python.readme.io
Acknowledgements · Pedantic Python
https://pedantic-python.readme.io/docs/acknowledgements
One statement per line. PEP 8 - Official Style Guide for Python Code](http:/ www.python.org/dev/peps/pep-0008/) * [Google's Python Style Guide](http:/ google-styleguide.googlecode.com/svn/trunk/pyguide.html) * [The Hitchhiker’s Style Guide](http:/ docs.python-guide.org/en/latest/writing/style/) by [Kenneth Reitz](http:/ kennethreitz.org/) * [Code Like a Pythonista: Idiomatic Python](http:/ python.net/ goodger/projects/pycon/2007/idiomatic/handout.html).
pedantic-python.readme.io
Theory of whitespaces · Pedantic Python
https://pedantic-python.readme.io/docs/theory-of-whitespaces
One statement per line. Always surround binary operators with a single space on either side, 1. Assignment (`=`) 2. Augmented assignment (` =`, `-=`) 3. Comparisons (`= `, ` `, ` `, `!
pedantic-python.readme.io
Object types · Pedantic Python
https://pedantic-python.readme.io/docs/object-types
One statement per line. Object type comparisons should always use `isinstance()` instead of comparing types directly. [block:code] { codes: [ { code: # Bad nif type(obj) is type(1): n print 'obj is of type int' n n# Good nif isinstance(obj, int): n print 'obj is of type int', language: python } ] } [/block].
pedantic-python.readme.io
Line length · Pedantic Python
https://pedantic-python.readme.io/docs/line-length
One statement per line.
pedantic-python.readme.io
Import statements · Pedantic Python
https://pedantic-python.readme.io/docs/import-statements
Nfrom subprocess import Popen, PIPE , n language : python n } n ] n} n[/block] nArrange * import statements* in the order the modules are referenced in the program. If that is not possible then enlist them in an alphabetical order or an order that has some logical meaning attached.,excerpt:It allows us to access code in another module.,slug:import-statements,type:basic,title:Import statements}. One statement per line. It allows us to access code in another module.
pedantic-python.readme.io
List comprehension · Pedantic Python
https://pedantic-python.readme.io/docs/list-comprehension
One statement per line. It provides a powerful and a concise way to work with iterables.
pedantic-python.readme.io
Dictionaries · Pedantic Python
https://pedantic-python.readme.io/docs/dictionaries
One statement per line. It is a key-value pair data structure.
SOCIAL ENGAGEMENT