Completely INNOCENT Indentation question
Caleb Hattingh
caleb1 at telkomsa.net
Thu Oct 14 22:55:28 EDT 2004
Actually, it should be trivial.
1. Set the preferance in your editor
2. Write a preprocessor (in python) that you supply with your program as
a command-line argument
Your preprocessor de-dents the code. Tracebacks will still be meaningful,
because you are not changing line numbering. BTW, The code-folding in ViM
can be set to correspond to indent-level, which means you can fold and
unfold all constructs to a specific depth. Magic.
Python makes me very lazy. Writing a report in LaTeX today, it was
actually easier for me to make up a syntax for tagging math symbols (put
into comments in the LaTeX source), and extract those and build a List Of
Symbols with a python preprocessor before texification, rather than find
(and figure out how to use) the correct LaTeX package for that. More
magic.
On 13 Oct 2004 20:28:00 -0700, valued customer <scooterm at hotmail.com>
wrote:
>> > Is there a way in python to indicate that you want your
>> > "base level of indentation" to be four spaces instead of
>> > zero?
>
>> I don't think so. Just out of curiosity, why would you want to do that?
>
> The question was just to make sure I hadn't overlooked some
> feature or setting of the programming language that would enable
> what I had asked about (short of introducing any of the various
> language constructs that we all can imagine and you need not
> elaborate here).
>
> As far as 'why would anyone want to do that' one reason that
> never fails is *personal preference* ... there probably isn't
> a stylistic or programming practice in existence that can't be
> explained at least partially by that. Therefore if someone asks,
> there must be at least *that* reason.
>
> For those who are not satisfied with that kind of answer, here
> is an example:
>
> Suppose you are editing source code in such a way
> that you only want *comments* to be flush left, and the rest of
> the code to be indented.
>
> (but Why would you want do that?)
>
> Because you work with a text editor that shows an 'outline'
> of your code based on the indentation, and you want the outline
> structure to be reflected in the comments.
>
> ### documentation
> """ This is a python script that does some stuff.
> Not only does it do stuff, it's documented stuff.
> """
> ### initialize python
> import foo
> import bar
>
> ### do some stuff
> print foo.frobilize()
>
> ### do some other stuff
> print bar.babelize()
>
> ### end of python
>
>
> Yes the question may remain ... why would anyone wanna do
> that? Well, there are reasons. Whatever the justifications
> may be, the 'additional language statements' workaround will
> apparently have to suffice.
>
> Thanks for the input though.
More information about the Python-list
mailing list