首页 > 解决方案 > Python list 和 int 仅在调试时有效

问题描述

我正在编写一个代码,在运行时给我一个dropd只有 1 个项目的列表,一个age应该是 int 的变量继续一个字符串。

当我在调试模式下使用代码时,我注意到如果我只执行列表dropd行,那么它会给我正确的项目,如果我age = int(agee)单独执行,那么它会给我一个 int 作为结果。

这是怎么回事?

    if sistema_selected == 2:
        self.driver.switch_to.frame(self.driver.find_element_by_xpath("//iframe[@data-id='1']"))
        ...
        time.sleep(3)

        try:
            print('CPF Valido')

            self.driver.find_element_by_xpath('//*[@id="mudarMatricula"]/div/div/select').click()

            dropd = self.driver.find_elements_by_xpath(
                '/html/body/div[2]/div[2]/div[2]/div[4]/div/form/
                 div[1]/div/div/div/div[2]/div[1]/h3/span[1]/div/div/select/option')


            i = 0
            for item in dropd:
                time.sleep(1)
                item.click()

                ...
                agee = idade_split[idade_split.index('Anos') - 1]
                age = int(agee)
                ...

                if age < 75:
                    idade_plc = Label(frame_idade, text=age, borderwidth=1, relief="groove")
                    idade_plc.grid(row=i + 1, column=0, sticky=EW)
                elif age > 75:
                    idade_plc = Label(frame_idade, text=age, borderwidth=1, relief="groove", bg='red')
                    idade_plc.grid(row=i + 1, column=0, sticky=EW)
                nome_plc = Label(frame_nome, text=nome)
                nome_plc.grid(row=0, column=1, sticky=EW)
                ...

        # IF THE CLIENT CODE IS WRONG
        except (NoSuchElementException, UnexpectedAlertPresentException):
            print('CPF Invalido')

标签: pythondebuggingpycharm

解决方案


推荐阅读