+ 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")

30th Sep 2017, 6:43 PM
warlord
warlord - avatar
4 Respuestas
+ 7
@Rick this is what I tried 😞 didn't work just showed none but I wrote and showed the content of the file
1st Oct 2017, 5:04 PM
warlord
warlord - avatar
+ 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
30th Sep 2017, 7:11 PM
warlord
warlord - avatar
+ 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()
30th Sep 2017, 7:15 PM
Rick
Rick - avatar
+ 3
Maybe you should print the file instead the function
30th Sep 2017, 7:04 PM
Rick
Rick - avatar