user2405029
user2405029

Reputation: 1

Python Files worked well but now giving error in IDLE 3.2

I wrote some python code 6 months ago on a Linux system. It worked perfectly, but now I installed IDLE 3.3 for Mac and I'm getting a lot of errors like "inconsistent use of tabs and spaces in indentation" Invalid syntax: on print command etc...

Does any one have an idea what can be wrong?

Upvotes: 0

Views: 104

Answers (2)

game writer guy
game writer guy

Reputation: 11

I had this same evil problem last week. I blame IDLE... I think it displays tabs funny* so I thought my code was clean even when it was inconsistent.

  • I recommend opening your code in a text editor you're familiar with. (Or use Microsoft Word and turn on the display of special characters http://www.addbalance.com/word/nonprinting.htm .) When I did this, I found I could see the inconsistencies clearly. Because of IDLE's display peculiarities I couldn't see them in IDLE. Clean the code in the text editor and see if IDLE behaves better afterward.
  • After cleaning, check your settings in Options > Configure IDLE > Fonts/Tabs.
  • I haven't had problems since doing the above, so I assume IDLE is reading my current indentation method and following that method going forward. Somehow you and I got into a mode where IDLE got confused and was putting in indentation that was inconsistent with what had gone before. This could've happened because I used spaces at one point, fixed it, and IDLE thought I was a space-indenter instead of a tab-indenter.
  • Using IDLE 3.7.4 for Windows 32-bit.

*I have recreated my problems (inadvertently) and now I am sure IDLE was inserting spaces every time I hit the tab key. (FYI, spaces is the Python standard, but I haven't been following that.) On top of that, when I navigated the cursor through the tabbed indents with the arrow keys, IDLE was stepping through them like they were made of spaces (!). And lastly, it was putting in FOUR spaces and displaying them as EIGHT. This evil design decision cost me at least a half-hour. The bad indents looked identical to the good ones, and deleting the erroring indents and replacing them with new ones was also completely futile. Quite frustrating.

Upvotes: 1

DXsmiley
DXsmiley

Reputation: 539

"inconsistent use of tabs and spaces in indentation" means that your indentation uses a combination of tabs and spaces. Change all your indentation to tabs OR spaces to fix this.

In python 3+ print is no longer a keyword. It's a function, so you have to call it as so:

print("Hello World!")

With the argument within parenthesis.

Upvotes: 1

Related Questions