import os os.rmdir("myfolder")
import os if os.path.exists("myfile.txt"): os.remove("myfile.txt") else: print("The file does not exist")
import os os.remove("myfile.txt")
contents = {"aa": 12, "bb": 21} with open("myfile2.txt", "w+") as file: file.write(json.dumps(contents))
with open('myfile2.txt', "r+") as file: contents = json.load(file) print(contents)
contents = {"aa": 12, "bb": 21} with open("myfile1.txt", "w+") as file: file.write(str(contents))
with open('myfile1.txt', "r+") as file: contents = file.read() print(contents)
with open("myfile.txt") as file: for line in file: print(line)
file = open('myfile.txt', 'r') for i, line in enumerate(file, start=1): print("Number %s: %s" % (i, line))