J
J
Jlad2021-07-21 15:10:49
Python
Jlad, 2021-07-21 15:10:49

Invalid syntax error

I am new to Python 3 (on which I write, which I have installed), I don’t understand what the error is, I didn’t find my case on the Internet.
The code:

import os

dirpath = os.getcwd()

open('Test', 'w') as file:
    file.write('data')

Error count: File "Learn1.py", line 5
open('Test', 'w') as file:
^
SyntaxError: invalid syntax

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stefan, 2021-07-21
@Jlad

import os

dirpath = os.getcwd()

with open('Test', 'w') as file:
    file.write('data')

M
Mikhail Krostelev, 2021-07-21
@twistfire92

open ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question