can anybody tell me what has changed | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

can anybody tell me what has changed

file = open("newfile.txt", "r") print("Reading initial contents") print(file.read()) print("Finished") file.close() file = open("newfile.txt", "w") file.write("Some new text") file.close() file = open("newfile.txt", "r") print("Reading new contents") print(file.read()) print("Finished") file.close()

27th Mar 2019, 4:41 AM
čƒ”č»’č±Ŗ
čƒ”č»’č±Ŗ - avatar
1 Resposta
+ 2
What do you mean, what has changed? If you run the code on Sololearn, the file newfile.txt probably won't exist, so you can't open and read it. Here's how you can check if the file exists: try: file = open("newfile.txt", "r") print("Reading initial contents") print(file.read()) print("Finished") file.close() except FileNotFoundError: print('File doesn\'t exist') Let me know if this doesn't answer your question
27th Mar 2019, 6:01 AM
Anna
Anna - avatar