diff --git a/blah.txt b/blah.txt new file mode 100644 index 0000000..82dd31b --- /dev/null +++ b/blah.txt @@ -0,0 +1 @@ +€K. \ No newline at end of file diff --git a/blah2.txt b/blah2.txt new file mode 100644 index 0000000..dde5455 --- /dev/null +++ b/blah2.txt @@ -0,0 +1 @@ +€K. \ No newline at end of file diff --git a/counter.py b/counter.py index 38ec816..397479e 100644 --- a/counter.py +++ b/counter.py @@ -16,7 +16,7 @@ def update_counter(file_name, reset=False): file_name: the file that stores the counter to be incremented. If the file doesn't exist, a counter is created and initialized to 1. - reset: True if the counter in the file should be rest. + reset: True if the counter in the file should be reset. returns: the new counter value >>> update_counter('blah.txt',True) @@ -30,7 +30,15 @@ def update_counter(file_name, reset=False): >>> update_counter('blah2.txt') 2 """ - pass + if reset == True or exists(file_name) == False: + count = 1 + else: + f = open(file_name, 'rb+') + f.seek(0, 0) + count = load(f) + 1 + + dump(count, open(file_name, 'wb')) + return count if __name__ == '__main__': if len(sys.argv) < 2: