Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Errors when using Spyder
#1
Hi,

I am learning how to use Python (I have previous coding experience with R), and started using Spyder. I am getting unexpected errors when trying to run for loops or if statements (I would probably get similar errors for other things too). This is an example:

for a in range(1,10):
	print(a)
And the error:

for a in range(1,10):
  File "<ipython-input-96-c0095e732a72>", line 1
    for a in range(1,10):
                         ^
SyntaxError: unexpected EOF while parsing
The weird thing is that when running this script from terminal, it does work! There is no error at all and the output is correct. Why would it only be giving an error in Spyder? I have looked for unwanted spaces or tabs after the ":" and there are none. My indentation also seems ok... Thanks for your help.
Reply
#2
The two for loops are not same. The latter one is missing:
print(a)
for block cannot be empty, that will always give errors. It needs to contain something, even if just an (indented!) pass statement.
Reply
#3
(Jan-24-2018, 07:08 PM)j.crater Wrote: The two for loops are not same. The latter one is missing:
print(a)
for block cannot be empty, that will always give errors.

I was simply printing the error message, I am not running two for loops. Oh I see what my error is, it is that I was trying to run the code line by line, and therefore by running the first line of the loops, it is like I tried to run an empty loop. Is there a way to run code line by line in Spyder, but such that the content of a loop will run along with the first line? That's how it works when using RStudio, for coding in R.
Reply
#4
Yes, that is what was going on!
I don't use Spyder, but a quick search returned this. So you can use the debugger, which will effectively work as a line by line code execution. If there are alternative options perhaps another user who is familiar with Spyder can help better.
Reply
#5
Great! Thank you for your help
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020