Python教程

Python字典操作

本文主要是介绍Python字典操作,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

    def ac_upgrade_ftp(self, version=None, ftp_mode=True, ftp_info={}):
        """
        通过FTP获取版本文件升级
        :param version:需要升级的版本文件名称
        :param ftp_mode:True为匿名,False为不匿名,默认为True
        :param ftp_info:参数包括
            ftp_ip:必选参数
            ftp_port:必选参数
            ftp_username:ftp_mode不匿名必选
            ftp_password:ftp_mode不匿名必选
        :return:
        """
        ftp_info = {
            'ftp_ip': '192.168.100.1',
            'ftp_port': '22',
            'ftp_username': 'ad0min',
            'ftp_password': 'Acc0ton123',
            'version': ''}
        uti.tab_enter('utilities', 'system_upgrade')
        time.sleep(2)
        ftp_must_param_anymous = ['ftp_ip', 'ftp_port']
        ftp_must_param_user = ['ftp_ip', 'ftp_port', 'ftp_username', 'ftp_password']

        if version is None or ftp_mode is None:        #判断版本信息和升级方式是否为空,为空则直接退出
            return

        if ftp_mode:
            for pararm_m in ftp_must_param_anymous:        #判断参数在不在anymous参数列表中并且判断参数在不在字典中
                if pararm_m not in ftp_info.keys():
                    return
        else:
            for pararm_m in ftp_must_param_user:
                if pararm_m not in ftp_info.keys():
                    return

        if ftp_mode:
            self.click(By.XPATH, x_uti_su_up_via_ftp_yes_rd)
            if ftp_info.setdefault('ftp_ip', None) is not None:     #如果key不在字典中,则用default值插入key。如果key在字典中,返回key的值,否则默认
                self.ccs(By.XPATH, x_uti_su_up_via_ftp_ip_ip, ftp_info.get('ftp_ip'))   #返回指定键的值,如果该键不存在,返回默认值
            self.ccs(By.XPATH, x_uti_su_up_via_ftp_port_ip, ftp_info.setdefault('ftp_port', 22))
            self.ccs(By.XPATH, x_uti_su_up_via_ftp_file_ip, version)
        else:
            self.click(By.XPATH, x_uti_su_up_via_ftp_no_rd)
            self.ccs(By.XPATH, x_uti_su_up_via_ftp_name_ip, ftp_info.get('ftp_username'))
            self.ccs(By.XPATH, x_uti_su_up_via_ftp_pass_ip, ftp_info.get('ftp_password'))

            if ftp_info.setdefault('ftp_ip', None) is not None:
                self.ccs(By.XPATH, x_uti_su_up_via_ftp_ip_ip, ftp_info.get('ftp_ip'))
            self.ccs(By.XPATH, x_uti_su_up_via_ftp_port_ip, ftp_info.setdefault('ftp_port', 22))
            self.ccs(By.XPATH, x_uti_su_up_via_ftp_file_ip, version)
        self.click(By.XPATH, x_uti_su_up_via_ftp_upload_rd)


这篇关于Python字典操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!