added 6 working example used for testing file IO
This commit is contained in:
parent
9651042bb2
commit
e13412be98
|
@ -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()
|
|
@ -0,0 +1,4 @@
|
|||
f = open("demofile.txt", "r")
|
||||
print(f.read())
|
||||
f.close()
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
f = open("demofile.txt", "r")
|
||||
print(f.read(5))
|
||||
f.close()
|
||||
|
|
@ -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()
|
||||
|
|
@ -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()
|
||||
|
|
@ -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()
|
||||
|
Loading…
Reference in New Issue