I'd like to use "semantic indentation"

bartc bc at freeuk.com
Sat Sep 30 15:14:01 EDT 2017


On 30/09/2017 19:12, Stefan Ram wrote:
>    I would like to write source code similar to:
> 
> country( 'USA' )
>    state( 'Alabama' )
>      town( 'Abbeville' )
>      town( 'Addison' )
>    state( 'Arizona' )
>      town( 'Apache Junction' )
>      town( 'Avondale )
>      town( 'Benson' )
> 
>    using "semantic indentation".
> 
>    It seems I can't do this with Python.
> 
>    Is there any workaround?

  def country(x): print("C:",x)
  def state(x): print("S:",x)
  def town(x): print("T:",x)

  def fn(*a): pass

  fn(
    country( 'USA' ),
      state( 'Alabama' ),
        town( 'Abbeville' ),
        town( 'Addison' ),
      state( 'Arizona' ),
        town( 'Apache Junction' ),
        town( 'Avondale' ),
        town( 'Benson' )
    )


This pretends they are arguments to a dummy function. But it probably 
won't work with anything that isn't also an expression.


-- 
bartc





More information about the Python-list mailing list