indentation preservation/restoration

smichr at gmail.com smichr at gmail.com
Tue Jan 3 00:23:28 EST 2006


Steven D'Aprano wrote:

> With a little bit of work, this could be expanded to add redundancy for
> not just indentation and numeric literals, but also string literals,
> keywords, operators, and anything else.

When I copy and assign to variable 'post' the reply posted here on
c.l.p. starting with "On Mon, 02" and ending with "- \nSteven." and run
it through the hidden() function below with the indices indicated, I
can see what you were really thinking.

The point is well taken: one must consider leading space as an
important part of the code.  This is just one of those things that's so
easy to shift around, however. You don't have to work very hard with an
editor's text manipulations to lose it.

That's life. I know.
/c

###
def hidden(t,indx):
    msg=[]
    for i in indx:
        msg.append(t[i])
    return ''.join(msg)
thought=[40, 47, 51, 106, 179, 180, 181, 182, 395, 396, 399,
1129, 1143, 1194, 1224, 1225, 1226]
print hidden(post,thought)
###




More information about the Python-list mailing list