allowing braces around suites

Kjetil Torgrim Homme kjetilho at yksi.ifi.uio.no
Mon Aug 30 22:43:12 EDT 2004


[Michael Sparks]:
>
>   The solution isn't to change the language in my eyes, the solution
>   is to produce better tools. After all, the following is legal
>   syntax in python if you really want close markers:
>   
>   end = None
>   for ch in "hello":
>      if ch == "l":
>         print "Rhubarb"
>      end
>      print ch,
>   end

that's a really cool trick!  perhaps a little prettier than the
established "# end if", but like the comment it has no effect on
Python's own code validation, so it's strictly not much of an
improvement.  but it inspired me to beget this evil hack:

  1  from block_end import end
  2
  3  def test():
  4      if True:
  5          print 'hello world'
  6          end('if')
  7  end('def')
  8
  9  test()

when you run this code, you'll get the error message:
block_end.IndentationError: Missing if on line 5, end on line 6

the module does _very_ rudimentary parsing of the source code and only
flags errors during run-time.  I'm not saying this is useful, but it
was fun to write :-)

since the module is just shy of hundred lines, I'm not including it
here.  please refer to this URL if you're interested in looking at the
implementation.

    http://heim.ifi.uio.no/~kjetilho/hacks/block_end.py

-- 
Kjetil T.



More information about the Python-list mailing list