On Sat, 24 May 2008 13:12:13 +0200, Johannes Bauer wrote: > Carl Banks schrieb: > >> p = myfunction() >> if p: >> print p >> >> (I recommend doing it this way in C, too.) > > This is okay for if-clauses, but sucks for while-loops: > > while (fgets(buf, sizeof(buf), f)) { > printf("%s\n", buf); > } > > is much shorter than > > char *tmp; > tmp = fgets(buf, sizeof(buf), f); > while (tmp) { > printf("%s\n", buf); > tmp = fgets(buf, sizeof(buf), f); > }
Can be written in Python as: from functools import partial # ... for buf in iter(partial(f.read, buf_size), ''): print '%s\n' % buf Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list