def process_code(code): indentLevel = 0 indentedRows = [] for row in (r.strip() for r in code.split('\n')): if (not row): continue if row == 'BEGIN': indentLevel += 1 elif row == 'END': indentLevel -= 1 else: indentedRows.append(indentLevel * ' ' + row) return '\n'.join(indentedRows) exec process_code(''' print "Kaslu na level" for a in xrange(3): BEGIN for b in xrange(4): BEGIN print a * b END END print "Vse v poradku" ''')Tak co, Petře, furt problémy?