Re: indentation preservation/restoration



On Mon, 02 Jan 2006 14:19:15 -0800, smichr 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,

What a great idea! I had a similar problem, your scheme could be adapted
to solve that too. I accidentally deleted all the numeric literals from my
Python code, and Python is fragile in this regard. So we could have a
"number code" appended to a script which could be used to rebuild the
script if necessary: e.g. a code like "E,D,CA" means the fourth token of
the fifth line is 31.

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. Using compression and
error-correcting codes should mean that your Python scripts will then be
safe from absolutely anything short of deleting the entire file -- and for
that, you have backups.



--
Steven.

.



Relevant Pages

  • Re: Python indentation
    ... > I am a beginner in Python, and am wondering what is it about the indentation ... > in Python, without which python scripts do not work properly. ... In many languages, such as C or Perl, you can write readable code, but ... but the script is much more readable than the Perl counterpart ...
    (comp.lang.python)
  • Re: indentation preservation/restoration
    ... 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. ... So go to see the source code of the HTML page in your editor and you will get the lost spaces. ...
    (comp.lang.python)
  • Re: perl to python
    ... sed and perl can let you do all that quick command line stuff. ... into a full blown script. ... scripts, call it from the python interpreter, whatever I need. ... If I stick to the traditional unix approach, ...
    (comp.lang.python)
  • Re: Learning Tkinter
    ... and how the command option is used to call the function callback. ... gui programming to see if the python programs I have written can be made ... search their computer for this file, execute the python code and then ... This is the meaning of the test on __name__: this magical variable is set to the string '__main__' if and only if the current script is the top-most one, i.e the one you ran python on. ...
    (comp.lang.python)
  • Correct way to handle independent interpreters when embedding in a single-threaded C++ app
    ... The Python interpreter is ... interpreter and provides an extension module to expose ... manage each script runs in a new interpreter. ... globals that could cause issues. ...
    (comp.lang.python)