Generate labels for a multi-level outline
castironpi at gmail.com
castironpi at gmail.com
Wed May 7 10:07:07 EDT 2008
'''
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
More information about the Python-list
mailing list