In Pycharm I keep running into this error:
TabError: inconsistent use of tabs and spaces in indentation
I know its a problem with tabs/spaces.
I want:
if len(myresults)==0:
print("TEST")
Whenever I type, pressing enter after every line typed I actually type:
if len(myresults)==0:
print("TEST")
Causing this error. How do I fix it? Here are my setting s for pycharm:
I'm probably missing something obvious, but I simply cannot find it.
Try,
Go to Settings --> Editor --> Code Style --> Python --> Tabs and Idents
.
Here activate (checkbox) Use tab character
AND Smart tabs
Thats works for me.
I'm using Pycharm and Jupyter Notebook and had the same problem with both of them. I could not fix it with "convert Indents", So I uninstalled some of the modules that I was using in my programm and reinstall them and worked for me.
I'm using Pycharm 2019.1. For me, this error constantly appeared always I pressed Enter to write a new line, and I have to manually rewrite every indentation in order to disappear the red sub-lines that indicate error. I fixed it by analyzing the full code into another text editor (kate editor in my case, but you can use another one). I verified there's some indentations written as [TAB] and the most of them written as four simple spaces. So I replaced all indentations written as [TAB] by indentations written as four spaces (most of the editors replace by using [Ctrl R] shortcut) and... voilà. Everything works fine. Note: I couldn't do the replace into Pycharm editor itself. Apparently pycharm editor does not differentiate a [Tab] of four spaces when you try replace by [Ctrl R]. Hope it help future users.
What worked for me:
Together with:
For reformatting the file: Ctr+Alt+L -> 'Code cleanup' on either selected text or whole file (depending on what is needed)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.