diff --git a/blah.txt b/blah.txt new file mode 100644 index 0000000..ba8c4c4 --- /dev/null +++ b/blah.txt @@ -0,0 +1,2 @@ +I3 +. \ No newline at end of file diff --git a/blah2.txt b/blah2.txt new file mode 100644 index 0000000..1cc9408 --- /dev/null +++ b/blah2.txt @@ -0,0 +1,2 @@ +I2 +. \ No newline at end of file diff --git a/counter.py b/counter.py index 1e2fb56..b5c2c38 100644 --- a/counter.py +++ b/counter.py @@ -15,7 +15,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) @@ -29,7 +29,15 @@ def update_counter(file_name, reset=False): >>> update_counter('blah2.txt') 2 """ - pass + f = open(file_name, 'r+') + if reset or not exists(file_name): + counter = 1 + else: + counter = load(f) + 1 + f.seek(0,0) + dump(counter, f) + + return counter if __name__ == '__main__': if len(sys.argv) < 2: