forked from piyush01123/Daily-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sol.py
52 lines (45 loc) · 1.27 KB
/
sol.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
from absl import app
class Reader:
def __init__(self, file):
self.content = open(file, 'r').read()
self.read_char_num = 0
self.offset = 0
self.file = file
def read7(self):
x = self.read_char_num
self.read_char_num+=7
return self.content[x:x+7]
def readN(self, n):
txt = ""
read7 = self.read7()
txt+=read7
while len(txt)<n and read7 != "":
read7 = self.read7()
txt+=read7
self.read_char_num=self.offset+n
self.offset+=n
return txt[:n]
def main(argv):
print('Testing read7')
reader = Reader('hello.txt')
print(reader.read7())
print(reader.read7())
print(reader.read7())
print(reader.read7())
print(reader.read7())
print('Testing readN')
reader = Reader('hello.txt')
print('N=4', reader.readN(4))
print('N=0', reader.readN(0))
print('N=2', reader.readN(2))
print('N=3', reader.readN(3))
print('N=10', reader.readN(10))
print('N=1', reader.readN(1))
print('Testing readN')
reader = Reader('hello.txt')
print('N=9', reader.readN(9))
print('N=0', reader.readN(0))
print('N=2', reader.readN(2))
print('N=3', reader.readN(3))
if __name__=='__main__':
app.run(main)