added 6 working example used for testing file IO

This commit is contained in:
Sylvain PILLOT 2024-02-15 23:19:45 +01:00
parent 9651042bb2
commit e13412be98
6 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,3 @@
f = open("demofile.txt", "w")
f.write("Hello! Welcome to demofile.txt\nThis file is for testing purposes.\nGood Luck!\n")
f.close()

View File

@ -0,0 +1,4 @@
f = open("demofile.txt", "r")
print(f.read())
f.close()

View File

@ -0,0 +1,4 @@
f = open("demofile.txt", "r")
print(f.read(5))
f.close()

View File

@ -0,0 +1,9 @@
f = open("demofile2.txt", "a")
f.write("Now the file has more content!")
f.close()
#open and read the file after the appending:
f = open("demofile2.txt", "r")
print(f.read())
f.close()

View File

@ -0,0 +1,9 @@
f = open("demofile2.txt", "a")
f.write("Now the file has more content!")
f.close()
#open and read the file after the appending:
f = open("demofile2.txt", "r")
print(f.read())
f.close()

View File

@ -0,0 +1,9 @@
f = open("demofile3.txt", "w")
f.write("Woops! I have deleted the content!")
f.close()
#open and read the file after the overwriting:
f = open("demofile3.txt", "r")
print(f.read())
f.close()