-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path31 - File Operations in Python.py
More file actions
220 lines (112 loc) · 6.57 KB
/
31 - File Operations in Python.py
File metadata and controls
220 lines (112 loc) · 6.57 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Getting Started with File Operation in Python Programmig Language
#r => read
#r+
#w=> write
#w+
#a=>append
#a+
fp = open("input.txt","r") #name of text file,the mode in which we want to open ths file
content = fp.read() # this read function always return in terms of string
print(content)
"""
Scholarship Notes
TSS Sameer Aatmanirbhar scholarship for Under Graduate 2021-2022
Protean e-Gov Renewal Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)
Publish Date : 15-03-20
Protean e-Gov Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)
Pragati Scholarship Programme For Girls Students pursuing Under Graduate Course
Arvind Fashions Limited ITI Scholarship Scheme 2021-2022
Publish Date : 24-02-2022
Arvind Fashions Limited UG Scholarship Scheme 2021-2022
Sandvik Coromant Girls Scholarship Program (21-22)
AIA Scholarship Programme For Undergraduate Course
AIA Scholarship Programme For B.E/B.Tech Course
Astral Foundation Scholarship For Undergraduate Courses (2021-2022)
Astral Foundation Scholarship For B.E/B.Tech Course (2021-2022)
Publish Date : 28-02-2022
Astral Foundation Renewal Scholarship For Under Graduate Course (2021-2022)
Astral Foundation Renewal Scholarship For B.E/B.Tech Course (2021-2022)
Timken Scholarship for B.E./B.Tech Students (2021-2022)
Timken Renewal Scholarship for B.E./B.Tech Students (2021-2022)
H.G. Infra Engineering Ltd. Scholarship for Undergraduate Courses
H.G. Infra Engineering Ltd. Scholarship for B.E./B.Tech Course
2 years programme:-
18000 only recorded
22000 live+recorded
1 year programme:-
Recorded 6-7 month-11000
+ live:- 16000
12 month:- 22000
"""
print("_______________")
content = fp.read()
print(content)
"""
_______________
Scholarship Notes
TSS Sameer Aatmanirbhar scholarship for Under Graduate 2021-2022
Protean e-Gov Renewal Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)
Publish Date : 15-03-20
Protean e-Gov Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)
Pragati Scholarship Programme For Girls Students pursuing Under Graduate Course
Arvind Fashions Limited ITI Scholarship Scheme 2021-2022
Publish Date : 24-02-2022
Arvind Fashions Limited UG Scholarship Scheme 2021-2022
Sandvik Coromant Girls Scholarship Program (21-22)
AIA Scholarship Programme For Undergraduate Course
AIA Scholarship Programme For B.E/B.Tech Course
Astral Foundation Scholarship For Undergraduate Courses (2021-2022)
Astral Foundation Scholarship For B.E/B.Tech Course (2021-2022)
Publish Date : 28-02-2022
Astral Foundation Renewal Scholarship For Under Graduate Course (2021-2022)
Astral Foundation Renewal Scholarship For B.E/B.Tech Course (2021-2022)
Timken Scholarship for B.E./B.Tech Students (2021-2022)
Timken Renewal Scholarship for B.E./B.Tech Students (2021-2022)
H.G. Infra Engineering Ltd. Scholarship for Undergraduate Courses
H.G. Infra Engineering Ltd. Scholarship for B.E./B.Tech Course
2 years programme:-
18000 only recorded
22000 live+recorded
1 year programme:-
Recorded 6-7 month-11000
+ live:- 16000
12 month:- 22000
"""
content = fp.read(45)
print(content)
"""
Scholarship Notes
TSS Sameer Aatmanirbhar s
"""
content = fp.readlines() # in case of read command it prints the content in terms of "string" while in case of readlines it writens in terms of "LIST"
print(content)
print(type(content))# <class 'list'>
"""
['\tScholarship Notes\n', '\n', 'TSS Sameer Aatmanirbhar scholarship for Under Graduate 2021-2022\n', '\n', 'Protean e-Gov Renewal Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)\n', 'Publish Date : 15-03-20\n', '\n', '\n', 'Protean e-Gov Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)\n', '\n', '\n', 'Pragati Scholarship Programme For Girls Students pursuing Under Graduate Course\n', '\n', '\n', 'Arvind Fashions Limited ITI Scholarship Scheme 2021-2022\n', 'Publish Date : 24-02-2022\n', '\n', 'Arvind Fashions Limited UG Scholarship Scheme 2021-2022\n', '\n', '\n', 'Sandvik Coromant Girls Scholarship Program (21-22)\n', '\n', 'AIA Scholarship Programme For Undergraduate Course\n', '\n', 'AIA Scholarship Programme For B.E/B.Tech Course\n', '\n', '\n', 'Astral Foundation Scholarship For Undergraduate Courses (2021-2022)\n', '\n', '\n', 'Astral Foundation Scholarship For B.E/B.Tech Course (2021-2022)\n', 'Publish Date : 28-02-2022\n', '\n', '\n', 'Astral Foundation Renewal Scholarship For Under Graduate Course (2021-2022)\n', '\n', '\n', 'Astral Foundation Renewal Scholarship For B.E/B.Tech Course (2021-2022)\n', '\n', '\n', 'Timken Scholarship for B.E./B.Tech Students (2021-2022)\n', '\n', 'Timken Renewal Scholarship for B.E./B.Tech Students (2021-2022)\n', '\n', 'H.G. Infra Engineering Ltd. Scholarship for Undergraduate Courses\n', '\n', 'H.G. Infra Engineering Ltd. Scholarship for B.E./B.Tech Course\n', '\n', '\n', '2 years programme:-\n', '18000 only recorded\n', '22000 live+recorded\n', '\n', '1 year programme:-\n', 'Recorded 6-7 month-11000\n', '+ live:- 16000\n', '12 month:- 22000\n', '\n', '\n', '\n', '\n', '\n', '\n']
"""
content = fp.readlines()
print(content[:5]) # Slicing operation ( i eant to print initial first five lines only )
"""
['\tScholarship Notes\n', '\n', 'TSS Sameer Aatmanirbhar scholarship for Under Graduate 2021-2022\n', '\n', 'Protean e-Gov Renewal Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)\n']
""" # So here by usig slicing operation it's printing onlr initial 5 lines
# So readlines will return the list and every line will be an element in the list not on the basis of fullstop while on the basis of new line )
# and python is making new line as an element on the basis of next line and shown as \n'
content = fp.readline() #by using only readline command only we can print the first line only, again not on the basis of fullstop while on the basis of a new line
print(content)
"""
Scholarship Notes """
content = fp.readline()#On use further it will start printing from next line
print(content)
"""
Scholarship Notes
TSS Sameer Aatmanirbhar scholarship for Under Graduate 2021-2022
"""
content = fp.readline() # So by using this readline command agaian and again according to condition we can print next line further
print(content)
"""
Scholarship Notes
TSS Sameer Aatmanirbhar scholarship for Under Graduate 2021-2022
Protean e-Gov Renewal Scholarship Scheme for students pursuing B.E/B.Tech (2021-2022)
"""
for x in fp:
print(x)