Python "why" questions

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Aug 21 10:54:19 CEST 2010


On Fri, 20 Aug 2010 09:21:25 +0200, Kai Borgolte wrote:

> Sorry about my previous posting with wrong references, this one should
> be better.
> 
> Steven D'Aprano wrote:
> 
>>A simple example: Using zero-based indexing, suppose you want to indent
>>the string "spam" so it starts at column 4. How many spaces to you
>>prepend?

As AK pointed out, I totally messed up the example by talking about 
column 4 then giving an example of column 5. Sigh.

0123456789
    spam


> No, you won't want to indent a string so it starts at column 4. You
> simply want to indent the string by four spaces. Like in PEP 8:
> 
> /Use 4 spaces per indentation level./

I don't see what PEP 8 has to do with anything here. Code is not the only 
thing that needs indenting, and 4 was just a mere example chosen at 
random. I might be pretty-printing a table of numbers, I might be drawing 
a text-based maze, I could be writing a function to left-fill strings 
with some arbitrary character, e.g left-fill with asterisks:

01234567
****spam

Besides, PEP 8 is merely a coding standard, not a law of nature. Some 
people might choose other coding standards, such as two-space indents, 
eight-spaces, or even (gasp! horror!) tabs.



> And of course your text editor will number the columns beginning with
> one, so the string starts at column 5.

Ah, text editors. I'm glad you mention that...

My text editor of choice is kwrite, which suits me fine, but it has one 
obnoxious, painful design choice. It indexes characters from one, so when 
I have the cursor at the left-hand margin and haven't typed anything, it 
says I'm at position 1. Consequently, if I want to know how many 
characters are in a line (and you'd be amazed how frequently I need to do 
this!), I can't just glance at the cursor position, I have to remember to 
subtract one from whatever the cursor position says.



-- 
Steven



More information about the Python-list mailing list