Skip to content Skip to sidebar Skip to footer

Python Problem: Opening And Closing A File Returns A Syntax Error

Hi guys I've fonund this useful python script that allows me to get some weather data from a site. I'm going to create a file and the dataset indide. Something is not working. It r

Solution 1:

Looks like you have a whitespace problem in there. Check the whitespace of the file - see where spaces and tabs are. If there are both tabs and spaces in the file, convert them all to spaces.

f.close should be at the same indentation level as f = open('wunder-data.txt', 'w')


Solution 2:

The line with the f.close() isn't line 42, so are you sure this is the code that gives the error?

Also, Python seems to process a program received on stdin, is this your intention?


Solution 3:


Solution 4:

I had a similar Error showing syntax error in 3.8 just now. And it turns out, my syntax error was a missing closing parenthesis in code above the highlighted line. So, line 42 is not what Question Putter should be looking at. Perhaps, there is actually a syntax error somewhere above in the code.


Solution 5:

I had the same problem today 2020(October), and I just checked the code above the close() function. I found I hadn't closed a bracket earlier. So the error is in the code above the function and not the actual line specified.


Post a Comment for "Python Problem: Opening And Closing A File Returns A Syntax Error"