Skip to main content

Create a file and write in it







Open file

file = open("text.txt",'w')
frase = input("Write something")
file.write(frase)
file.close()
import os
if "text.txt" in os.listdir():
    print("The file has been created")
file = open('text.txt')
content = file.read()
print("I found this in the text.txt file:",content)
file.close()
Write somethingHello World
The file has been created
I found this in the text.txt file: Hello World

Comments