Python Forum
SyntaxError when i used interpreter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SyntaxError when i used interpreter
#1
Hi.
I'm just a beginner, and I have a problem that I couldn't understand the reason.

f = open ("C:/doit/newfile.txt", 'w')
for i in range(1,11):
    data = "%d line. \n" % i
    f.write(data)
f.close()
I was practising file input and output.
when I tried to run on windows command prompt, it was successful.
On the other hand, on python interpreter (Python3.7.2), it had a syntax error like below.

>>> f = open ("C:/doit/newfile.txt", 'w')
>>> for i in range(1,11):
...     data = "%d line. \n" % i
...     f.write(data)
... f.close()
  File "<stdin>", line 4
    f.close()
    ^
SyntaxError: invalid syntax
Please let me know the reason.
Reply


Messages In This Thread
SyntaxError when i used interpreter - by hydor - Jan-16-2019, 05:26 PM
RE: SyntaxError when i used interpreter - by hydor - Jan-16-2019, 05:59 PM
RE: SyntaxError when i used interpreter - by hydor - Jan-16-2019, 06:21 PM

Forum Jump:

User Panel Messages

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