A Suggestion for Python Colon Syntax

Alex Martelli aleaxit at yahoo.com
Thu Dec 21 22:23:00 CET 2000


"Jay O'Connor" <joconnor at cybermesa.com> wrote in message
news:mailman.977429044.1109.python-list at python.org...
>
> >It is really useful (needed) if you wanted to write 2 statements on 1
> >line.  I don't know why that would be needed, but . . .
>
> This is useful for small anonymous functions such as used for filter()
> and map().

'Anonymous functions' in Python are normally lambdas, which are
only made up of one expression (no statements); I guess one _might_
construct a 'small anonymous function' via module new, but even then,
I can't quite see how constructing the needed codeobject is specifically
eased by '2 statements on 1 line'.

As I see things, the option to put 2 statements on one line has the
specifical stylistic benefit of letting _me_, as a programmer, decide
how I want to best invest a scarce resource -- the number of program
lines I can comfortably view onscreen at once (ability to read and
follow a given function or class drops rapidly if it doesn't fit for
reading on 1 or 2 screenfuls; yet a few strategically placed empty
lines, comments, docstrings, might be a better investment of that
resource for clarity purposes).

However, the strongly dominant default Python style does _not_
include this usage -- one has to be aware of that... if one's code
is meant for others' consumption, following strongly established
precedents has its own advantages!-)


Alex






More information about the Python-list mailing list