indentation preservation/restoration

smichr at gmail.com smichr at gmail.com
Mon Jan 2 23:19:15 CET 2006


I have (inadvertently) wiped out the functionality of my personal
python snippets by eliminating leading space. I have also just visited
http://www.python.org/tim_one/000419.html and saw a piece of code with
the indentation gone. Python code is fragile in this regard. One
solution that occurs to me is that a "indentation code" could be
appended to a script which could be used to rebuild the script if
necessary. e.g. if we let letters represent the number of spaces before
a line and numbers to indicate how many lines have that spacing, then
A2E2A1 could represent the leading space on the code,

# A Hello Program
def hi():
    msg = 'hello world!'
    return msg
print hi()

If the line returns are gone (as they are at the url above) then this
wouldn't work and perhaps the number of characters on each line could
be encoded as well. I'm not sure what the best way to do that would be.


I'm not sure where the best time and place to add such a coding to file
would be, however. If you  do as I did to my library (anyone?) then
having the code placed at the bottom of the script as save time
wouldn't have helped in the recovery.  Placing the code with scripts
that are placed on the web or archived might be smart.

Any thoughts?

/c




More information about the Python-list mailing list