I am trying to reuse an opened file which is declared inside the constructor instance of a class but I guess I am doing something logically wrong. For instance consider the following example
class Temp:
def __init__(self):
self.open_file_ = open('periodic_status','r')
def function1(self):
new_file = self.open_file_
for i in new_file:
print 'test1'
def function2(self):
for j in self.open_file_:
print 'test2'
if __name__ == '__main__':
obj1 = Temp()
obj1.function1()
obj1.function2()
In the above program I can print test1 but I am not able to print the statement test2. Can some one explain me the logic.
Thanks