alternatives to making blocks like { } or other ??

Tim Williams timothy.williams at nvl.army.mil
Wed May 19 08:20:11 EDT 2004


"Paul McGuire" <ptmcg at austin.rr._bogus_.com> wrote in message news:<sjDqc.108220$NR5.92596 at fe1.texas.rr.com>...
> "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


I have to put my 2 cents in here. I love Python, but the one thing I
miss is using {} or something to enclose blocks. I edit in emacs
python-mode, and believe in indentation, but sometimes I'll
inadvertently change a line of code's indentation and it throws the
logic off. I found a bug in one of my programs recently where a line
of code should have been outside of an 'if', but wasn't because I hit
TAB one too many times. A {} block would've caught that. I know that's
just being careless, but I need all the help I can get!

One thing I have done is to put a '#' at the end of the block so I
know not to indent the next line when adding code.



More information about the Python-list mailing list