Re: Tabs, spaces, and indentation
Wed, 13 Apr 1994 10:31:35 +0200

> As an indentation-based language, Python has problems with the
> relationship between tabs and spaces. Reading UNIX files on the Mac,
> or vice versa, tends to result in files that either look wrong,
> parse wrong, or both. The UNIX world tends to use 1 tab = 8 spaces,
> while the Mac world tends to use 1 tab = 4 spaces. Yes, you can give
> a command to the Python parser to change its tab/space relationship,
> but that's messy when you have multiple included files.
> I suggest that Python allow indentation with either.
> tabs or spaces, but complain if it sees both used for indentation
> in the same file. Comments?

People who want to see 4-space indentation on Unix may have no choice
but to mix spaces and tabs -- most editors' auto-indent mode optimizes
8 spaces into a tab.

My recommendation is to always use tabs on the Mac -- then it will
look good on the Mac and at least parse correctly everywhere.

For the same reason I recommend always using tabs on Unix as well
(thus indenting by 8 positions there), but the majority of Python
users seem to be against me.

Note that the Mac code contains a hack which attempts to get the tab
size from an editor "ETAB" resource but I don't know how succesful
this is since there are many different editors around... (Code
attached, comments welcome.)

--Guido van Rossum, CWI, Amsterdam <>
URL: <>

======================= macguesstabsize.c =======================
#include <MacHeaders>
#include <string.h>

/* Interface used by tokenizer.c */

char *path;
char s[256];
int refnum;
Handle h;
int tabsize = 0;
s[0] = strlen(path);
strncpy(s+1, path, s[0]);
refnum = OpenResFile(s);
/* printf("%s --> refnum=%d\n", path, refnum); */
if (refnum == -1)
return 0;
h = GetIndResource('ETAB', 1);
if (h != 0) {
tabsize = (*(short**)h)[1];
/* printf("tabsize=%d\n", tabsize); */
return tabsize;