[Python-Dev] Python FAQ: Why doesn't Python have a "with" statement?

C. Titus Brown ctb at msu.edu
Thu Jun 19 13:54:51 CEST 2008

On Wed, Jun 18, 2008 at 10:55:32PM -0700, Alex Martelli wrote:
-> On Wed, Jun 18, 2008 at 9:58 PM, Cesare Di Mauro <cesare at pronto.it> wrote:
-> > Very very, interesting. Thanks. :)
-> >
-> > Somebody thinks that Python is unsuitable to implement a DSL: IMO your example prove the contrary. :D
-> As long as you're willing to do the "DSL" within the strictures of
-> Python syntax, it's OK - not quite as flexible as LISP or Scheme or
-> even Ruby, but better than most;-).  I did design and implement "DSL"s
-> in Python (mostly specialized class trees with suitable metaclasses,
-> decorators &c) in many jobs in my recent past, I'll admit -- it never
-> feels as free-flowing as Scheme did back when I used THAT, but, close
-> enough to make my jobs successful!-)

It's pretty easy to put a simple syntax remapper around Python, too;
this is what twill does.  So, for example, this:

setlocal username <your username>
setlocal password <your password>

go http://www.slashdot.org/
formvalue 1 unickname $username
formvalue 1 upasswd $password

code 200     # make sure form submission is correct!

translates very directly to

setlocal('username', '...')
setlocal('password', '...')

formvalue('1', 'unickname', username)
formvalue('1', 'upasswd', password)


which is DSL-ish enough for me...

More generally, I've never understood why some people insist that
certain features make Ruby better for DSLs -- are code blocks really
that important to DSLs?  Or is it just the lack of parens??

C. Titus Brown, ctb at msu.edu

More information about the Python-Dev mailing list