Indentation


Every programming language has a way of organizing the code so it appears in readable chunks whitespace, braces, explicit line termination (such as the semicolon in C). Python uses indents as a formal part of the language, and lines end with a hard return.

The rules on indentation are simple. Be consistent in how you indent. Use the same number of spaces to indent a block of code. If you need a statement that spans more than one line, use the backslash (\) to continue the line. Here's an example of Python's indentation rule at work:

file = open("./data.txt", "r") while 1:   line = file.readline()   if not line:     break   print line, file.close 

Python's indentation rules may take a little getting used to if you're coming from another programming language such as Perl, but they will make your code more readable and thus easier to maintain. With any project, it's good to keep in mind that you may not always be the person in charge of the code, and memory fades, so make it readable at all times.



SUSE Linux 10 Unleashed
SUSE Linux 10.0 Unleashed
ISBN: 0672327260
EAN: 2147483647
Year: 2003
Pages: 332

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net