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

前端 未结 29 838
小鲜肉
小鲜肉 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:31

    No. Indentation-as-grammar is an integral part of the Python language, for better and worse.

    0 讨论(0)
  • 2020-12-31 14:31

    I agree with justin and others -- pick a good editor and use spaces rather than tabs for indentation and the whitespace thing becomes a non-issue. I only recently started using Python, and while I thought the whitespace issue would be a real annoyance it turns out to not be the case. For the record I'm using emacs though I'm sure there are other editors out there that do an equally fine job.

    If you're really dead-set against it, you can always pass your scripts through a pre-processor but that's a bad idea on many levels. If you're going to learn a language, embrace the features of that language rather than try to work around them. Otherwise, what's the point of learning a new language?

    0 讨论(0)
  • 2020-12-31 14:31

    If you're looking for a recommendation for a Python IDE, after extensive research, I've been most happy with Wing Software's WingIDE:

    http://www.wingware.com/products

    There is a free trial version, so you have nothing to lose. It supports all the major OSes, and is only about $60 for the full version.

    I also like SciTE a lot, which is totally free, free, free!

    http://scintilla.sourceforge.net/SciTEDownload.html

    0 讨论(0)
  • 2020-12-31 14:32

    No. How would Python parse your script if there was a way to disable this?

    0 讨论(0)
  • 2020-12-31 14:32

    Check the options of your editor or find an editor/IDE that allows you to convert TABs to spaces. I usually set the options of my editor to substitute the TAB character with 4 spaces, and I never run into any problems.

    0 讨论(0)
  • 2020-12-31 14:35

    All of the whitespace issues I had when I was starting Python were the result mixing tabs and spaces. Once I configured everything to just use one or the other, I stopped having problems.

    In my case I configured UltraEdit & vim to use spaces in place of tabs.

    0 讨论(0)
提交回复
热议问题