In [28]:
import pickle


#increment couter
def incrementCounter():
    counter = pickle.load(open('counter','rb'))
    counter['counter']+=1
    pickle.dump(counter,open('counter','wb'))
    return counter['counter']
    

def readCounter():
    return pickle.load(open('counter','rb'))


def resetCounter():
    try:
        os.system('rm counter')
    except:
        pass
    
    counter = 0
    pickle.dump(counter,open('counter','wb'))
    return 0

In [27]:
resetCounter()


Out[27]:
0

In [23]:
incrementCounter()


Out[23]:
1

In [24]:
incrementCounter()


Out[24]:
2

In [29]:
readCounter()


Out[29]:
0

In [ ]: