#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    28
    Rep Power
    0

    List not changing in method


    So here's my code:
    Code:
    from libs import Config as lib_config
    import time as lib_time, pygame
    
    class Alarm:
    	def __init__(self):
    		pygame.mixer.init()
    		Config = lib_config.Config
    		self.Logger = lib_config.Logger
    		self.music_dir = Config.get('model_music', 'directory')
    		self.alarms = [[Config.get('model_alarm', 'alarm1_time'), Config.get('model_alarm', 'alarm1_song'), False],
    					[Config.get('model_alarm', 'alarm2_time'), Config.get('model_alarm', 'alarm2_song'), False]]
    		
    	def getAlarm(self):
    		return self.alarms
    		result = []
    		self.Logger.debug(str(self.alarms))
    		for (time, song, enabled) in self.alarms:
    			result.append([time, enabled])
    		return result
    		
    	def alarm(self):
    		localtime = lib_time.localtime()
    		time_current = lib_time.strftime('%H:%M', localtime)
    		current = 0
    		
    		for (time_alarm, song, enabled) in self.alarms:
    			if(time_alarm == time_current and enabled == True):
    				pygame.mixer.music.set_volume(1)
    				if pygame.mixer.music.get_busy():
    					pygame.mixer.music.stop()
    				pygame.mixer.music.load(self.music_dir + song)
    				pygame.mixer.music.play()
    				self.setAlarm(current)
    			current += 1
    				
    				
    	def setAlarm(self, alarm_number):
    		self.Logger.debug(str(self.alarms))
    		self.alarms[alarm_number][2] = not self.alarms[alarm_number][2]
    		self.Logger.debug(str(self.alarms))
    			
    	def setFirstAlarm(self):
    		self.setAlarm(0)
    		
    	def setSecondAlarm(self):
    		self.setAlarm(1)
    The problem is that when I'm calling getAlarm() after I have changed the boolean values in self.alarms, I get False when the output I'm getting from setAlarm is different. How is this possible?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    190
    Rep Power
    2
    With out looking in too much detail, this can't work:
    python Code:
    def getAlarm(self):
    	return self.alarms
    	result = []
    	self.Logger.debug(str(self.alarms))
    	for (time, song, enabled) in self.alarms:
    		result.append([time, enabled])
    	return result

    Once a function returns it ends. The code beneath return self.alarms never runs.

    -Mek
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    28
    Rep Power
    0
    Originally Posted by Mekire
    With out looking in too much detail, this can't work:
    python Code:
    def getAlarm(self):
    	return self.alarms
    	result = []
    	self.Logger.debug(str(self.alarms))
    	for (time, song, enabled) in self.alarms:
    		result.append([time, enabled])
    	return result

    Once a function returns it ends. The code beneath return self.alarms never runs.

    -Mek
    I know this and I did this because this function gets called in another class and I need to check what the value was it was getting. It's being outputted in another class, but look over this for now.

    Edit: I have found the problem and it was outside of this class, thanks for helping me though.

IMN logo majestic logo threadwatch logo seochat tools logo