Sep-08-2018, 10:48 PM
(This post was last modified: Sep-08-2018, 10:48 PM by hypersdevelopment.)
I'm making a Discord.py bot with a utilities package. In the utilities package, there are 3 files which are together causing the logic error.
""" Database.py ----------- Database format: { "SectionNameHere" : { "foo" : "bar" }, "2ndSectionNameHere" : { "foo" : "bar" }, "3rdSectionNameHere" : { "foo" : "bar" } } """ import json class database: def __init__(self, *args, **kwargs): self.args = args self.kwargs = kwargs self.data = None def set(self): with open("Resources/database.json", "r") as DB: self.clean() self._data = DB.read() self.data = json.loads(str(self._data)) def clean(self): with open("Resources/database.json", "r") as fData: oData = fData.read() with open("Resources.json", "w") as wData: wData.write(oData.replace("'", "\"")) def init(self): self.clean() self.set()(database.json)
{ "userdata" : { "help" : "nope" } }(Giveaway.py)
import random import Utilities.database as database class giveaway: def __init__(self, Name): self.reward = Name self.contestants = [] def contestantJoin(self, user): self.contestants.append(user) def chooseWinner(self): return random.choice(self.contestants) def delete(self): del self # If a giveaway is saved in memory, load it automaticly db = database.database() db.init() print(db.data["userdata"]["help"])Now this should print
Nope
once, but instead it prints Nope
twice.Output:nope
nope
I'm using python 3.6 Win7. Any help would be appreciated! Thanks in advance!