From f0834bcfaf80849884b0bc1a3772b3b99128b78a Mon Sep 17 00:00:00 2001 From: Andrew Macgregor Date: Tue, 16 Oct 2012 22:21:32 +0800 Subject: [PATCH] Conventions header was throwing inconsistent level warning. Fixed this and later headings to match rest of page. --- docs/writing/style.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/writing/style.rst b/docs/writing/style.rst index 58ce019..528eb2b 100644 --- a/docs/writing/style.rst +++ b/docs/writing/style.rst @@ -416,12 +416,12 @@ Then run it on a file or series of files to get a report of any violations. optparse.py:544:21: W601 .has_key() is deprecated, use 'in' Conventions -::::::::::: +---------------- Here are some conventions you should follow to make your code easier to read. Check if variable equals a constant ------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You don't need to explicitly compare a value to True, or None, or 0 - you can just add it to the if statement. See `Truth Value Testing @@ -455,7 +455,7 @@ list of what is considered false. print 'attr is None!' Access a Dictionary Element ---------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~ Don't use the ``has_key`` function. Instead use ``x in d`` syntax, or pass a default argument to ``get``. @@ -484,7 +484,7 @@ a default argument to ``get``. print d['hello'] Short Ways to Manipulate Lists ------------------------------- +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `List comprehensions `_ @@ -548,7 +548,7 @@ manually. Moreover, it is better optimized for iterators. Read From a File ----------------- +~~~~~~~~~~~~~~~~ Use the ``with open`` syntax to read from files. This will automatically close files for you. @@ -574,7 +574,7 @@ The ``with`` statement is better because it will ensure you always close the file, even if an exception is raised. Returning Multiple Values from a Function ------------------------------------------ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Python supports returning multiple values from a function as a comma-separated list, so you don't have to create an object or dictionary and pack multiple