diff --git a/tail.py b/tail.py index 24f69d0..fa206a1 100644 --- a/tail.py +++ b/tail.py @@ -28,7 +28,7 @@ class Tail(object): ''' Represents a tail command. ''' - def __init__(self, tailed_file): + def __init__(self, tailed_file, open_mode = 'r'): ''' Initiate a Tail instance. Check for file validity, assigns callback function to standard out. @@ -38,6 +38,7 @@ def __init__(self, tailed_file): self.check_file_validity(tailed_file) self.tailed_file = tailed_file self.callback = sys.stdout.write + self.open_mode = open_mode def follow(self, s=1): ''' Do a tail follow. If a callback function is registered it is called with every new line. @@ -46,7 +47,7 @@ def follow(self, s=1): Arguments: s - Number of seconds to wait between each iteration; Defaults to 1. ''' - with open(self.tailed_file) as file_: + with open(self.tailed_file, self.open_mode) as file_: # Go to the end of file file_.seek(0,2) while True: