为了账号安全,请及时绑定邮箱和手机立即绑定

在 Python 中使用一个函数(方法)的返回值到另一个函数(方法)

在 Python 中使用一个函数(方法)的返回值到另一个函数(方法)

子衿沉夜 2023-04-18 17:41:26
我正在尝试使用从函数 get_reg_check_type 返回的值“str(check)”,并在另一个函数 get_status_type 中使用它。我怎样才能做到这一点?#---- Get Register Check Type # 如果寄存器存在且解锁则返回“CHECK”;“CHECK_NRF”如果寄存器不存在或被锁定    def get_reg_check_type(self, addr, lock=definitions.LockTest.LOCK):        check = "CHECK_NRF" # NOTE: if items (bits) are locked, check will stay set to CHECK_NRF        for items in self.register_field_collection:            for item in items:                # Bit exists and is unlocked - return "CHECK"                if (addr == item.register_address):                    if ((lock == definitions.LockTest.LOCK) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW])) or \                       ((lock == definitions.LockTest.A  ) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW, definitions.RegWriteLock.FRU])) or \                       ((lock == definitions.LockTest.AB ) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW, definitions.RegWriteLock.FRU])) or \                       ((lock == definitions.LockTest.ABC) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW, definitions.RegWriteLock.FRU, definitions.RegWriteLock.FEBU])):                        check = "CHECK"        return str(check)            def get_status_type(self):        if self.check = "CHECK_NRF"            status_value = 8'h44        else:            status_value = 8'h40        return status_value
查看完整描述

1 回答

?
繁花不似锦

TA贡献1851条经验 获得超4个赞

如果可以在同一个类中找到这些函数,则可以先调用get_reg_check_typethen get_status_type。


def get_reg_check_type(self, addr, lock=definitions.LockTest.LOCK):

        check = "CHECK_NRF" # NOTE: if items (bits) are locked, check will stay set to CHECK_NRF

        for items in self.register_field_collection:

            for item in items:

                # Bit exists and is unlocked - return "CHECK"

                if (addr == item.register_address):

                    if ((lock == definitions.LockTest.LOCK) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW])) or \

                       ((lock == definitions.LockTest.A  ) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW, definitions.RegWriteLock.FRU])) or \

                       ((lock == definitions.LockTest.AB ) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW, definitions.RegWriteLock.FRU])) or \

                       ((lock == definitions.LockTest.ABC) and (item.register_write_lock in [definitions.RegWriteLock.NO, definitions.RegWriteLock.FRW, definitions.RegWriteLock.FRU, definitions.RegWriteLock.FEBU])):

                        check = "CHECK"

        self.checked = str(check) # set the value

        

    def get_status_type(self):

        print(self.checked) # get the value

        if self.check = "CHECK_NRF"

            status_value = 8'h44

        else:

            status_value = 8'h40

        return status_value


查看完整回答
反对 回复 2023-04-18
  • 1 回答
  • 0 关注
  • 264 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信