str % vals -like idea but for statements (was Re: PEP-308 a "simplicity-first" alternative)

Anders Hammarquist iko at cd.chalmers.se
Wed Feb 12 11:24:00 EST 2003


In article <Pine.GSO.4.51.0302120436120.15100 at techunix.technion.ac.il>,
Beni Cherniavsky  <cben at techunix.technion.ac.il> wrote:

>Allow adding a class-like indented block of code to any simple statement,
>with the semantics that the block is evaluated first and the statement is
>the evaluated with the block's variables in scope.  Here is how you do a
>conditional expression morea readably with it::
>
>    print "Complex text about", n, things where:
>        if n == 1:
>            things = "thing"
>        else:
>            things = "things"
>    print "More code..."

To me, this reads like a crippled lambda that allows statements,
but it is definitely a lot more readable than any of the other
proposals so far. Though I think that it should be "return" rather
than the FORTRANy "things =", but that doesn't work for your later
general case. Or does it? Hmm, something like:

    bar = property(get_bar, set_bar) get_bar, set_bar = where:
        def get_bar(self):
            some_code
        def set_bar(self, val):
            other_code
	return get_bar, set_bar

I don't particularly like the assignment that would be needed
(spam = where:) though.

/Anders

-- 
 -- Of course I'm crazy, but that doesn't mean I'm wrong.
Anders Hammarquist                                  | iko at cd.chalmers.se
Physics student, Chalmers University of Technology, | Hem: +46 31 88 48 50
G|teborg, Sweden.           RADIO: SM6XMM and N2JGL | Mob: +46 707 27 86 87




More information about the Python-list mailing list