-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFile Handeling part 1.py
54 lines (45 loc) · 1.1 KB
/
File Handeling part 1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#;==========================================
#; Title: File handeling part 1
#; Author: @AyemunHossain
#;==========================================
#Read a file :
file = open("story.txt","r")
containt=file.read()
file.close()
print(containt)
#read file line by line :
file=open("story.txt","r")
[print(i,end="") for i in file]
file.close()
#Read specific amount of bit :
file = open("story.txt","r")
content=file.read(10)
file.close()
print(content)
#write a file :
file=open("story2.txt","w")
file.write("This story is about the boy who live.\nHis name is Harry Potter.\n")
file.close()
#check out that file
file = open("story2.txt","r")
content=file.read()
file.close()
print(content)
#append a file
file=open("story2.txt","a+")
file.write("The boy was cursed by \"Voldemort\".\n")
file.close()
file = open("story2.txt","r")
content=file.read()
file.close()
print(content)
#append a file and read:
file=open("story2.txt","a+")
file.write("\"Voldemort\" Killed Harry's parents.\n")
file.seek(0)
content=file.read()
print(content)
#Print the actual file name :
f=open("story2.txt",'r')
print(f.name)
f.close()