Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10839 > unrolled thread
| Started by | "Christian Gelinek" <cgelinek@radlogic.com.au> |
|---|---|
| First post | 2011-08-04 13:55 +0930 |
| Last post | 2011-08-04 22:35 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Inconsistencies with tab/space indentation between Cygwin/Win32? "Christian Gelinek" <cgelinek@radlogic.com.au> - 2011-08-04 13:55 +0930
Re: Inconsistencies with tab/space indentation between Cygwin/Win32? Thorsten Kampe <thorsten@thorstenkampe.de> - 2011-08-04 07:18 +0200
Re: Inconsistencies with tab/space indentation between Cygwin/Win32? Nobody <nobody@nowhere.com> - 2011-08-04 22:35 +0100
| From | "Christian Gelinek" <cgelinek@radlogic.com.au> |
|---|---|
| Date | 2011-08-04 13:55 +0930 |
| Subject | Inconsistencies with tab/space indentation between Cygwin/Win32? |
| Message-ID | <mailman.1875.1312432561.1164.python-list@python.org> |
Hi all, I have a problem running some python program using version 2.6.4 (or version 2.7.2, I tried both) from the Win7 command line - it never finishes due to an infinite loop. The thing is, when I run the same program through Cygwin which uses Python version 2.6.5, it exits the loop at some point. I came to try this after I realised that in some of the sources (it is a rather big program using many source files, most of them being created by others from a Linux environment), the indentation is mixed tabs/spaces where the assumed tab size is 8 spaces. Reading on the Python website, a tab size of 8 is default anyway, so I would have assumed it should work... does that mean that one tab equals 2 indents?!? I myself never use tabs to indent Python code but let my editor do a tab-to-4-spaces conversion when I press <TAB>. I find it at least confusing to read that Python expects a tab size of 8 but at the same time uses 4 spaces for one indent level. Or maybe I am completely on the wron track here? Any ideas on how to get the thing to run under (real) Windows, hopefully without having to edit existing sources of people who left our company ages ago?
[toc] | [next] | [standalone]
| From | Thorsten Kampe <thorsten@thorstenkampe.de> |
|---|---|
| Date | 2011-08-04 07:18 +0200 |
| Message-ID | <MPG.28a44a22d78ade3c989850@news.individual.de> |
| In reply to | #10839 |
* Christian Gelinek (Thu, 4 Aug 2011 13:55:37 +0930) > Any ideas on how to get the thing to run under (real) Windows, > hopefully without having to edit existing sources of people who left > our company ages ago? python -t "Issue a warning when a source file mixes tabs and spaces for indentation in a way that makes it depend on the worth of a tab expressed in spaces. Issue an error when the option is given twice." Thorsten
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-08-04 22:35 +0100 |
| Message-ID | <pan.2011.08.04.21.35.01.55000@nowhere.com> |
| In reply to | #10839 |
On Thu, 04 Aug 2011 13:55:37 +0930, Christian Gelinek wrote: > I find it at least confusing to read that Python expects a tab size of 8 but > at the same time uses 4 spaces for one indent level. Or maybe I am > completely on the wron track here? 4-column indents are a convention, not a rule. You can use however many columns you like, and you don't even need to be consistent about it; you can use 2 columns for one "block" and 4 columns for another. Python only cares about "indented more than the previous line" and "indented to a depth matching an outer level of the code". 8-column tab stops are a rule, due to it being such a long-standing convention that some software and hardware has 8-column tab stops hardwired (and anything which allows tab stops to be configured normally defaults to 8 columns). > Any ideas on how to get the thing to run under (real) Windows, hopefully > without having to edit existing sources of people who left our company ages > ago? The only time you'll have problems is if you copy-and-paste code which was written using a mix of tabs and spaces and which assumed a different tab width. If code only ever uses tabs, the tab width doesn't matter. If code uses a mix of tabs and spaces and it actually works, it's correct according to Python's 8-column tab stops, even if that's not how the programmer's editor was set up. Also, copying blocks of code which start and end at the top-level (i.e. without indentation) will work regardless. Where it fails is if you copy indented code from e.g. a file which used a mix of spaces and 4-column tabs into a file which uses 8-column tabs. If you have existing code which uses a mix of tabs and spaces where tabs aren't 8 columns (or you aren't sure that they're 8 columns), your best bet is to reformat the code to avoid using tabs (on Unix: "pr -t -e", or "pr -t -e4" for 4-column tabs).
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web