Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- class Config:
- def __init__(self, file="config.pycfg"):
- self.file = file
- def get(self, key):
- f = open(self.file, "r")
- data = f.read()
- f.close()
- for line in data.splitlines():
- sp = line.split('=')
- if sp[0] == key:
- return sp[1]
- return None
- def add(self,key,amount=1):
- d = int(self.get(key))
- if d:
- self.set(key, d+amount)
- else:
- self.set(key, amount)
- def set(self, key, value):
- f = open(self.file, "r+")
- data = f.read()
- f.close()
- f = open(self.file, "w+")
- found_line = None
- for line in data.splitlines():
- sp = line.split('=')
- if sp[0] == key:
- found_line = line
- new = "%s=%s" % (key, value)
- if found_line:
- data = data.replace(found_line, new)
- else:
- data = "%s\n%s" % (data, new)
- f.write(data)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement