alternatives to making blocks like { } or other ??

Paul McGuire ptmcg at austin.rr._bogus_.com
Wed May 19 02:40:24 EDT 2004


"Grant Edwards" <grante at visi.com> wrote in message
news:slrncalqqf.8f2.grante at grante.rivatek.com...
> On 2004-05-18, CYBER <usenet at zly_adres.com> wrote:
> >> Of course there is another way!
> >>
> >> Just use # in front of your favourite block separator.
> >>
> >> I'm too lazy now to search the archives on who first suggested this,
> >> but it works:
> >>
> >> def something(x):
> >> #{
> >>     return x
> >> #}
> >
> > Thank you.
>
> You realize that was a joke, right?
>
<snip>

Actually, it was worse than a joke, in that it looks like it works, but
really doesn't.

If you thought this was somehow magically doing grouping by reading the
commented-out braces, you could end up doing things like:

if condition: #{
        do_something if condition is true
#} else: #{
        do_something if condition is false
#}

which would have some surprising results (both true and false "paths" are
executed, because they are really the same path, the condition-is-true
path).

So, no, CYBER, this doesn't really work, although most cases will not
complain, and *usually* do what you want.  But in general, don't even start
this habit, just use the language features as-designed.

-- Paul





More information about the Python-list mailing list