user3103923
user3103923

Reputation: 107

Resetting variables

So I'm trying to get my Point module to reset these variables after a game is finished which are outside the class Point:

    lotteryStart = time.time()
    players = []
    pot = 1

class Point:

     def load():
            # load the database into the bot
        dPoint = {} # dict for points
        for name in open("Point.DB","r").readlines():
           if len(name.strip())>0:
             name,point = name.split()
             dPoint[name] = int(point)
        Point.dPoint = dPoint
        Point.MINUTE = 60
        Point.HOUR = Point.MINUTE * 60
        Point.DAY = Point.HOUR * 24
        Point.YEAR = Point.DAY * 365 
        Point.timer = 15
        lotteryStart = time.time()
        pot = 1
        players = []

I try placing the same variables in my def load(): that's under the class but when using Point.load() the variables stay the same as before there load. Is there a way to get it set the variables to the original start.

Upvotes: 0

Views: 89

Answers (1)

barak manos
barak manos

Reputation: 30136

The following piece of code will not change the global variable 'x':

x = 1;
class Point:
    x = 2
print x # will print 1

In order to solve this, you have to explicitly declare 'global x' in the desired class or function:

x = 1;
class Point:
    global x
    x = 2
print x # will print 2

Upvotes: 1

Related Questions