I'd like to use "semantic indentation"

Joonas Liik liik.joonas at gmail.com
Sat Sep 30 14:31:10 EDT 2017


On 30 September 2017 at 21:12, Stefan Ram <ram at zedat.fu-berlin.de> 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' )
>
>
you can't get off quite as clean without sth like macropy..
but you can get close with custom contextmanagers.

with country( 'USA' ):
    with state( 'Alabama' ):
        town( 'Abbeville' )
        town( 'Addison' )

of course you need to write the contextmanager yourself..
and need to decide what the topmost level contextmanager will operate on
unless you want to do sth .. .probably quite nasty



More information about the Python-list mailing list