sys.modules is a dictionary that contains all loaded modules’ names as keys.
Archives for the Month of February, 2008
Learning Python: Chapter 17
Wednesday, 27 February 2008
Anonymous functions are declared with lambda instead of def.
Lambda definitions are expressions and may therefore not contain if-statements and the like.
map(foo, list1, list2, list3) is like [foo(*tuple) for tuple in zip(list1, list2, list3)].
By using yield instead of return to provide a return value, you create a function that returns a generator object that returns one [...]
Learning Python: Chapter 16
Friday, 22 February 2008
Perl
Python
my $x = 10;
sub foo
{
$x = 20;
}
x = 10
def foo():
global x
x = 20
Declaring a variable in a function as global is only necessary for reassignments, not for mere read-access.
def foo(x, y, z): pass
foo(10, 20, 30)
does the same as
[...]
Learning Python: Chapter 15
Thursday, 21 February 2008
A function definition may be put inside an if-block.
if DEBUG:
def do_something():
print ‘useful debug information’
do_some_work()
else:
def do_something():
do_some_work()
Learning Python: Chapter 14
Wednesday, 20 February 2008
Docstrings are available at runtime via the __doc__ attribute.
The reference count of any object is available via sys.getrefcount(object).
Learning Python: Chapter 13
Tuesday, 19 February 2008
while and for loops may have an else block that is executed if the loop terminates naturally, that is, not by a break statement.
There is a no-op statement called pass.
Assignments to variables do not return the assigned value; they are statements, not expressions.
You can build your own iterables by implementing a next method that raises [...]
Learning Python: Chapter 12
Monday, 18 February 2008
There is no switch statement.
Boolean AND, OR and NOT are really just and, or and not, there’s neither && nor || nor ! in Python.
Learning Python: Chapter 11
Saturday, 16 February 2008
Because Python doesn’t guess default values, a sequence assignment like fst, snd = some_sequence works iff some_sequence has length 2.
There is no auto-increment and no auto-decrement.
Names beginning with single or double underscore have special meaning.
Names of built-ins can be reassigned.
Combined comparisons for range checks: x < y <= z.
The Wisdom of Crowds
Friday, 15 February 2008
The Wisdom of Crowds:
The Wisdom of Crowds: Why the Many Are Smarter Than the Few and How Collective Wisdom Shapes Business, Economies, Societies and Nations, first published in 2004, is a book written by James Surowiecki about the aggregation of information in groups, resulting in decisions that, he argues, are often better than could have [...]
Learning Python: Chapter 10
Thursday, 14 February 2008
elsif is called elif.
Parens around boolean tests are optional.
A semicolon can be put at the end of any statement to make it look like C.
Parts of statements enclosed in parens, curlies or brackets may span over multiple lines.
Since parens may be wrapped around each expression, virtually anything can be spread over [...]
I Am a Strange Loop
A Short History of Nearly Everything