osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

I'd like to use "semantic indentation"


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