I need help here. 
my_file = with open("text.txt","r") as my_file:
my_file.write("Road To ~Sucess~")
Codecademy returns," Oops, try again. Your syntax doesn't look quite right. Check the Hint if you need help.
"
Console returns:
File "python", line 1
my_file = with open("text.txt","r") as my_file:
^
SyntaxError: invalid syntax
Tks a lot. 
1 Like
You’re trying to read the file instead of writing.
instead of "r"
as one of the parameters type in “w”`.
2 Likes
PS : I also tried this:
with open("text.txt","r") as my_file:
my_file.write("Road To Sucess")
and it also didn’t work.
1 Like
This:
my_file = with open("text.txt","w") as my_file:
my_file.write("Road To ~Sucess~")
doesn’t work, too.
1 Like
After those two lines print my_file
2 Likes
And this shouldn’t be there because the as statement takes car of the variable name.
1 Like
i have some problem in these page -_-
my code is :
my_file = with open(“text.txt”,“w”) as my_file:
my_file.write(“Road To ~Sucess~”)
print my_file()
but didn’t work to
what must i do?
1 Like
dave.n
10
On this line remove my_file =
1 Like
any idea why this code is not working ?? im getting an Invalid syntax error on line 1
with open(“text.txt”,“w”) as my_file
my_file.write(“this is my first file”)
print my_file
my_file.close()
1 Like
dave.n
12
Did you pass or you’re still stuck?
1 Like
FYI. My code is:
no need to close,because the with do it for us
my_list = [i**2 for i in range(1,11)]
for item in my_list:
with open("text.txt","w") as my_file:
my_file.write(str(item)+"\n")
1 Like
hello @baton134 you have to put a colon (
after -as my_file. that’s all
: colon : ok just so you know
Thank you so much I was spending hours and hours trying to figure it out. and you helped me understand it. Thank you.
1 Like