Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I had enough syntax errors appearing after a copy and paste that ended up with difficult to spot unaligned code that I decided to use Python only for little scripts and when I'm forced to use it and nothing else would do. The problem with Python is that editors don't have hints to autoalign the code for us. Same problem with templating languages like HAML and Slim which, oh the irony, were born for Rails. Nevertheless many people like Python and it's growing strong (maybe stronger as system/desktop language than for the web) so those problems of mine are not as big as I feel they are. But how do you survive to them or make them not happen? I'm sincerely interested.


I've found the same as you - pasting code from anywhere to a Python application comes with a risk. This risk is however not too different from other languages where you wouldn't want mixed spaces and tabs in your code either. In my opinion, Python just enforces good coding style. You might have been as the error messages I get is rather verbose telling me the linenumber with an exception "IndentationError: unexpected indent" or "IndentationError: unindent does not match any outer indentation level". The first is for wrong identation level and the second is for mixed tabs and spaces.

Anyways - to mitigate the risk of misaligned code. The usual thing is that the wrong type of indentation is used. I use sublime text and in that editor there's a button where I can convert tabs to spaces and vice versa. The other thing is that of misaligned code with your existing code. You can usually get some plugins that handle this for you. In Python I use the Anaconda-plugin with the 'Auto format' feature which aligns in accordance to the PEP-8 standard.


I must admit that I only really took to Python once I got IDE support (initially in Visual Studio with PVTS and for the last while with PyCharm).

I'm very happy with PyCharm.


Exactly, use PyCharm for auto-identing and this is no longer an issue. For shells, you can use bpython or IPython to the same effect.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: