Generate labels for a multi-level outline

castironpi at gmail.com castironpi at gmail.com
Wed May 7 14:07:45 EDT 2008


On May 7, 9:07 am, castiro... at gmail.com wrote:
> '''
> On May 6, 4:43 pm, pyt... at bdurham.com honoring:
>
> >>> a.next( )
> ( "I", )
> >>> a.throw( up )
> ( "I", "A" )
> >>> a.next( )
> ( "I", "B" )
> >>> a.next( )
> ( "I", "C" )
> >>> a.throw( down )
>
> ( "II", )
> '''
>
> #funny declaration
> class up( Exception ): pass
> class down( Exception ): pass
>
> def outline( ):
>     stack= [ 1 ]
>     while 1:
>         try:
>             yield stack
>             stack[ -1 ]+= 1
>         except up:
>             stack.append( 1 )
>         except down:
>             stack.pop( -1 )
>             stack[ -1 ]+= 1
>
> a= outline( )
> print a.next( )
> print a.throw( up )
> print a.next( )
> print a.next( )
> print a.throw( down )
> print a.throw( up )
> print a.throw( up )
> print a.next( )
> print a.next( )
> print a.throw( down )
>
> ##output:
>
> [1]
> [1, 1]
> [1, 2]
> [1, 3]
> [2]
> [2, 1]
> [2, 1, 1]
> [2, 1, 2]
> [2, 1, 3]
> [2, 2]
>
> ##
>
> cf.
>
> formatter.NullFormatter.format_counter
> formatter.NullFormatter.format_letter
> formatter.NullFormatter.format_roman

One execution of Python 3a4 included in built-ins.

Python 3.0
 win32
Type "help
>>> next
<built-in
>>>

Do you want send and throw in it too?



More information about the Python-list mailing list