-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilePractice.py
54 lines (43 loc) · 1000 Bytes
/
filePractice.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
f=open("practice.txt","w+")
f.write("Hi everyone\nwe are learning File I/O\nusing Java.\nI like programming in Java.\n")
f.seek(0)
data=f.read()
print(data)
new_data=data.replace("Java","Python")
print(new_data)
f.close()
f=open("practice.txt","w")
f.write(new_data)
f.close()
def check_for_word(word):
with open("practice.txt","r") as f:
data=f.read()
if(data.find(word) != -1):
print("found")
else:
print("not found")
def pos_of_word(word):
with open("practice.txt","r") as f:
data = True
line_no = 1
while data:
data=f.readline()
if(word in data):
print(line_no)
return
line_no+=1
return -1
check_for_word("learning")
pos_of_word("learning")
"""O/P
Hi everyone
we are learning File I/O
using Java.
I like programming in Java.
Hi everyone
we are learning File I/O
using Python.
I like programming in Python.
found
2
"""