python 函數返回多個參數的賦值方法

#定義函數
def Get_Counter_AllMeasureValue(self, inst_dg_address):    """    get all measure value ,as Frequency,period,duty,+width,-width,and so on...    :param inst_dg_address:    :return: Frequency,period,duty,+width,-width    :return:  all return value is  string    """    Frequency = 0.0    period = 0.0    duty = 0.0    p_width = 0.0    n_th = 0.0    rm1 = visa.ResourceManager();    ret = -9.0    try:        mi_1 = rm1.open_resource(inst_dg_address);    except:        rt_error("In DG_Counter_CMD.py DG:Get_Counter_Sensitive, open element1 resource error: %s" % inst_dg_address);        return False;    # 實際執行部分    mi_1.timeout = 10000;    ret = mi_1.query(':COUNter:MEASure?')    mi_1.close();    frequency = ret[:15]    period = ret[16:31]    duty = ret[32:47]    p_width = ret[48:63]    n_width = ret[64:79]    return frequency,period,duty,p_width,n_width得到函數的返回值方法:frq,perid,duty,p_wid,n_wid = DG_CMD.Get_Counter_AllMeasureValue(dut_dg_address)另外,debug調試的時候發現return 返回值是tuple 元組類型的,所以有多個返回值的 也能夠經過元組的方式訪問各個元組中的元素,由於元組的元素不能修改,所以也印證了爲何函數返回值是元組的緣由了
相關文章
相關標籤/搜索