-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdep_bad.py
More file actions
31 lines (24 loc) · 831 Bytes
/
Copy pathdep_bad.py
File metadata and controls
31 lines (24 loc) · 831 Bytes
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
class TextFileOperations:
def __init__(self,path):
self.path = path
def read_text_data(self):
with open(self.path, 'r') as file:
data = file.read()
return data
def write_text_data(self,data):
with open(self.path,'w') as file:
file.write(data)
class TextOperations:
def __init__(self,text_source):
self.text_source = text_source
self.data = self.text_source.read_text_data()
# Searches for a
def search_for_word(self, word):
return word in self.data
# Counts the occurrences of a word in the data
def count_occurences(self, word):
return self.data.count(word)
file = TextFileOperations("output.txt")
obj = TextOperations(file)
print(f"{obj.search_for_word('more')}")
print(f"{obj.count_occurences('be')}")