On Tue, Jan 24, 2012 at 10:24 AM, Ian Tickle <ianj...@gmail.com> wrote:
> reassuring air of finality!  Maybe a Python expert will answer this
> but I've often wondered, what happens if as some editors do
> (particularly if as I do you have to use different editors at
> different times depending on where you are working, such as on Windows
> working remotely from home or Linux at work), you could have a mixture
> of space and tab characters in the file?

Yes, this can happen.  In practice, one learns very quickly to
configure the text editors to prevent this kind of mix-up, i.e. by
always inserting spaces instead of tab characters.  In vim, for
instance, you can do this:

set expandtab
set tabstop=2

For CCTBX, the rule is to use two spaces as the indentation (tabs
strictly forbidden), and despite having multiple active contributors,
this is almost never a problem.  (The rule for most other Python
modules appears to be four spaces, which I personally find too wide.)
It becomes second nature after a while, just like adding a semicolon
at the end of each statement in C/C++/Java/etc.  I agree that it seems
annoying and confusing at first, but if you've ever tried to edit
someone else's C or Perl code where the indentation was totally
inconsistent, you'll quickly learn to appreciate Python's style.

> So does Python automatically expand the tabs to the
> equivalent number of spaces or (as in data input) are they treated as
> single characters?  And anyway how does Python know what tab stops my
> editors are set to and indeed how exactly my editors treat tabs?

Answers are "no" and "it doesn't", at least I don't think so.  The
safest thing (especially if you need to copy and paste code from any
other module) is to never use literal tabs.

-Nat

Reply via email to