'MyClass'对象没有属性'select_db_flag'错误

时间:2016-03-25 18:55:27

标签: python python-2.7

我需要一些帮助,因为我的当前代码存在问题。我正在尝试调用GoRight函数,但它会给我一个错误: AttributeError:'MyClass'对象没有属性'select_db_flag'

错误是跳到这一行:

if select_db_flag == True:

以下是我用来从move_right.py调用GoRight函数的代码:

import move_right

class MyClass(xbmcgui.WindowXML):
    def GoRight(self):
        move_right.GoRight(self)

以下是发现错误的代码:

import datetime
import time
import xbmc
import xbmcgui

prog_id = 0
select_db_flag = False
program_stop_minutes = 0
program_stop_time = 0
epg_time_1 = ''
epg_time_2 = ''
epg_time_3 = ''

def get_programming_times(self):
     if select_db_flag == True:
         select_db_flag = False



 def GoRight(self):
    program_button = [elem.control for elem in self.program_buttons]
    programs_id = list()
    program_width = list()
    positions_X = list()
    positions_Y = list()

    for elem in program_button:
        programs_id.append(elem.getId())
        positions_X.append(elem.getX())
        positions_Y.append(elem.getY())
        program_width.append(elem.getWidth())
    programs_id = map(str, programs_id)
    posX = map(str, positions_X)
    posY = map(str, positions_Y)
    program_width = map(str, program_width)

    for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
        if int(pos_X) == 375 and int(prog_width) == 1311:
            programs_width = 969
            self.getControl(int(prog_id)).setWidth(int(programs_width))
            program_width = self.getControl(int(prog_id)).getWidth()
            select_db_flag = True
            program_stop_minutes, program_stop_time, epg_time_1, epg_time_2, epg_time_3 = get_programming_times(self)


            if program_stop_time == epg_time_3:
                if program_stop_minutes == '00':
                    if program_width == 969:
                       program_width = 692

我在代码的顶部定义了select_db,但是当我收到错误时它没有帮助我。

你知道为什么我有错误,你知道如何解决它吗?

1 个答案:

答案 0 :(得分:0)

替换它:

If Now < [time]
    [code]
Else
    Timer.Enabled = False
End If

用这个:

/*global Draggable, TweenMax, Bounce*/

每次调用全局变量时都应该使用global,所以在其他函数中也可能需要def get_programming_times(self): if select_db_flag == True: select_db_flag = False

编辑: 注释中的其他问题修复:

def get_programming_times(self):
    global select_db_flag
    if select_db_flag == True:
         select_db_flag = False

这将修复错误,但可能会导致其他错误或返回错误的结果。

如果您从互联网上复制代码,请尝试理解它,而不是随意使用它。