python idioms: (was: a really cool python feature)
Neil Schemenauer
nascheme at enme.ucalgary.ca
Thu May 11 13:51:17 EDT 2000
Grant Griffin <g2 at seebelow.org> wrote:
>Forgive a possible newbie FAQ, but is there a page of Python
>idoms like this?
Python doesn't have too many idoms and that's a good thing.
string.join is not an idom. That function is for exactly that
usage. The only problem would be finding it in the library
reference. The only really useful idioms I can think of right
now are:
while 1:
something
if condition:
break
using default arguments to simulate closures:
def foo():
a = 1
def bar(a=a):
print a
bar()
and doing some stuff if the module is '__main__':
if __name__ == '__main__':
something
Can anyone think of more (ignoring tricks with lambda, reduce,
filter, and map)?
Neil
--
"Everyone can be taught to sculpt: Michelangelo would have had to
be taught how not to. So it is with the great programmers" -- Alan Perlis
More information about the Python-list
mailing list