indentation preservation/restoration

Claudio Grondi claudio.grondi at freenet.de
Mon Jan 2 17:38:42 EST 2006


smichr at gmail.com wrote:
> 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

Usually the problem can be solved by looking at the source code of an 
HTML page. The people programming Python are not always good 
Web-programmer and forget to put their code into textarea or pre tags in 
order to make the code pastable directly from the web page.

This seems also to be for the mentioned page the case. So go to see the 
source code of the HTML page in your editor and you will get the lost 
spaces.

Claudio



More information about the Python-list mailing list