Archives for posts tagged ‘python’
Friday, 7 March 2008
20 chapters of Python should be a foundation solid enough to let me start learning yet another language without mixing the new knowledge up. Well, at least I am gonna give it a try. So here’s what I found out while reading Programming Ruby.
When overriding a method in a subclass, the keyword super suffices on [...]
Tags: code, python, read
Posted in Uncategorized | No Comments »
Tuesday, 4 March 2008
Package imports require you to put __init__.py files in each directory in the package chain.
The modifier as provides a means of neatly aliasing package paths in import statements with short names.
Tags: code, python
Posted in Uncategorized | No Comments »
Monday, 3 March 2008
from-statements let you expose your code to the amout of namespace pollution you like:
from some_module import some_function (like use CGI qw(header); in Perl)
Symbol tables of modules are accessed through the dictionary named __dict__.
Tags: code, perl, python
Posted in Uncategorized | No Comments »
Sunday, 2 March 2008
after sifting through some slides about The Cobra Programming Language, I get the impression that Cobra might be a language worth keeping in mind.
Tags: blog, python
Posted in Uncategorized | No Comments »
Friday, 29 February 2008
sys.modules is a dictionary that contains all loaded modules’ names as keys.
Tags: code, python
Posted in Uncategorized | No Comments »
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 [...]
Tags: code, python
Posted in Uncategorized | No Comments »
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
[...]
Tags: code, perl, python, read
Posted in Uncategorized | No Comments »
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()
Tags: code, python
Posted in Uncategorized | No Comments »
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).
Tags: python
Posted in Uncategorized | No Comments »
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 [...]
Tags: python
Posted in Uncategorized | No Comments »