I'd like to use "semantic indentation"

Chris Angelico rosuav at gmail.com
Sat Sep 30 14:58:14 EDT 2017


On Sun, Oct 1, 2017 at 5:12 AM, 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' )
>
>   using "semantic indentation".
>
>   It seems I can't do this with Python.
>
>   Is there any workaround?

If the indentation has semantic significance, you shouldn't need to
say "country" or "state" or "town". I suggest this format:

USA:
    Alabama:
        Abbeville
        Addison
    Arizona:
        Apache Junction
        Avondale
        Benson

and then, as Paul suggested, write a simple parser to read it.

ChrisA



More information about the Python-list mailing list