New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spaces vs tabs #2888
Comments
Right now, there are no easy way to change the behavior.
The first 2 are just one line codemirror options that have to be added in the right place. Just to be sure, when using the notebook, you get tabs in the codecell, right ? Or indent/dedent is something is selected, or trigger tooltip or completion, but this is a detail. |
In current master, if you paste a code containing tabs, there is a visual indicator (arrow) to show you where the tabs are located |
Python either allows tabs or spaces for indentation. I prefer to use tabs. When I cut and paste tab-indented code into iPython, how can I get the tab key on the keyboard to insert a tab character into a cell? It appears by default with iPython that pressing tab on your keyboard inserts spaces into the cell. Then when you execute the cell this causes Python to complain about indentation. In the example below print statement was added in iPython and has space indentation while the other lines were copied from a pyCharm project with tab indentation.
File "", line 10 I think this is what vgoklani was trying to ask here. |
indeed :) |
I seem to be running into you a lot now. Is this you referenced in Phillip Cloud’s reply? http://stackoverflow.com/questions/10729210/iterating-row-by-row-through-a-pandas-dataframe From: Vishal Goklani [mailto:notifications@github.com] indeed :) — |
yup! |
Any news on this? I too would like to use tabs in the cells of my Jupyter notebooks so that I do not need to change the code between my editor and my notebooks. |
The Python Style Guide says don't use tabs. Same for Ruby, PHP and Java, as well as Google's style guides for CSS and C++. I just picked Python and the first five others I could find. A lot of effort has already been made to phase tabs out entirely, because they're problematic and don't do anything that can't easily be achieved with spaces. Tabs are only supported at all because old code contains them. New languages (and new filetypes for existing languages) should not allow tabs (except when using
It'd be more accurate to say that Python tolerates tabs, but strongly recommends using spaces. |
Here is a solution I found on stackoverflow: https://stackoverflow.com/questions/40861769/in-jupyter-notebook-how-to-change-auto-indent-to-tab-instead-of-4-spaces It's kind of amusing how some people can't seem to stop themselves from making preachy, unhelpful comments when these topics come up. |
to each their own, but it is def a PITA that different editors, e.g., vi vs. jupyter, handle this differently (at least with my settings; it's not their fault) and then it later cause my Python code to barf. if I were the king of Python I'd do something a little more intelligent there, like figuring out that when someone TABed they meant the same as when someone (invariably with carpal thumbal syndrome) typed 4 spaces. i.e., whitespace. that's what a human would do, right? well, maybe not you high school language teacher, but reasonable humans would see that and say, oh, i get it. personally, I don't understand why anyone would prefer to type exactly 4 spaces when they really mean 1 unit of indention, aka TAB. esp. with a language like Python what will barf if you accidentally type 3 or 5. that just seems unnecessarily complicated to me. hit the damn TAB key and get on with it. all that said, as a sw eng with 40 years experience in zillions of languages, notably C/C++, it is really jarring to back to a non-Python (or Scala) language where I have to add semicolons and curly braces. how quaint. (personally, I think Smalltalk had the best readability, but it is an acquired taste, like Lisp.) |
Hi,
I have a small issue when using the ipython notebook in the browser. I'm one of those people that likes to press tab, and unfortunately there are several instances when writing a for loop and incrementing a line, that the tabs get converted to spaces. And the end result is that I get an "IndentationError: unexpected indent". The solution is to move the code into sublime (or your text editor of choice), fix the tab/space issue, and then paste back into the notebook. Is there a workaround, surely I can't be the only person with this problem.
The text was updated successfully, but these errors were encountered: