July 30th, 2008 at 2:39pm |
Since Python treats a newline as a statement terminator, and since statements are often more then is comfortable to put in one line, many people do:
if foo.bar()['first'][0] == baz.quux(1, 2)[5:9] and \
calculate_number(10, 20) != forbulate(500, 360):
pass
You should realize that this is dangerous: a stray space after [...]
Read the rest of Using Backslash to Continue Python Statements
March 27th, 2008 at 12:10am |
On the Modules page of the Python docs, there is this code example:
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
Being new to Python, this code snippet confused [...]
Read the rest of The Python, The Print and The Comma
March 24th, 2008 at 8:32pm |
I’ve been using iText - the Java PDF library - a lot recently and seeing as I’ve been getting into Python I wanted something similar to iText for that. I managed to dig these up:
ReportLab - A PDF creation tool in the iText mould but the ReportLab site hasn’t been updated since 2005 so looks [...]
Read the rest of Python PDF tools
March 21st, 2008 at 4:10pm |
The Python language contains the OO concept of a class. Rather strangely, it only really does half the job in that it doesn’t provide a way to properly encapsulate your class’ members.
Take this Java class, for example:
class Steve
{
private String name;
public String getName()
[...]
Read the rest of Python and encapsulation
March 19th, 2008 at 11:42pm |
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the [...]
Read the rest of The Zen of Python