Is there a way around coding in Python without the tab, indent & whitespace criteria?

前端 未结 29 1025
小鲜肉
小鲜肉 2020-12-31 14:05

I want to start using Python for small projects but the fact that a misplaced tab or indent can throw a compile error is really getting on my nerves. Is there some type of s

29条回答
  •  爱一瞬间的悲伤
    2020-12-31 14:45

    In Python, indentation is a semantic element as well as providing visual grouping for readability.

    Both space and tab can indicate indentation. This is unfortunate, because:

    • The interpretation(s) of a tab varies among editors and IDEs and is often configurable (and often configured).

    • OTOH, some editors are not configurable but apply their own rules for indentation.

    • Different sequences of spaces and tabs may be visually indistinguishable.

    • Cut and pastes can alter whitespace.

    So, unless you know that a given piece of code will only be modified by yourself with a single tool and an unvarying config, you must avoid tabs for indentation (configure your IDE) and make sure that you are warned if they are introduced (search for tabs in leading whitespace).

    And you can still expect to be bitten now and then, as long as arbitrary semantics are applied to control characters.

提交回复
热议问题