Passing indented code to compile()

Lulu of the Lotus-Eaters mertz at gnosis.cx
Wed May 7 12:35:37 EDT 2003


"John Wilson" <tug at wilson.co.uk> wrote previously:
|"just working" it the apex of my ambition at the moment ;-)

There is a function I use in several variants of my smart ASCII markup
tools.  It looks at a code block (or anything), and pushes the block as
far left as possible, while maintaining relative indents.

    def LeftMargin(txt):
        """Remove as many leading spaces as possible from whole block"""
        for l in range(12,-1,-1):
            re_lead = '(?sm)'+' '*l+'\S'
            if re.match(re_lead, txt): break
        txt = re.sub('(?sm)^'+' '*l, '', txt)
        return txt

Yours, Lulu...

--
 mertz@  _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_    n o
gnosis  _/_/             Postmodern Enterprises            \_\_
.cx    _/_/                                                 \_\_  d o
      _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e






More information about the Python-list mailing list