+ 8
What the ? 😮 ( PLEASE HELP ) 😞
I thought it will open a new file and write hello world but the result is none I tried to to write the "w" (writing mode) without the " " to make it understand that it should write a new file but tells me it's not defined so i wrote it with the " " here's the code is that because it's a visual coding like it considers the file exist or doesn't exist please help def my_function(filename): f = open(filename,"w") f.write("hello world") f.close() print(my_function("hello.txt")) file = open("hello.txt","r")
4 Réponses
+ 7
@Rick this is what I tried 😞 didn't work just showed none but I wrote and showed the content of the file
+ 6
@Rick I tried to create the file with no content before I use the function but it the result was the same as the one in this code
+ 4
file = open("newfile.txt", "w")
file.write("This has been written to a file")
file.close()
file = open("newfile.txt", "r")
print(file.read())
file.close()
+ 3
Maybe you should print the file instead the function