追加到阵列失败

时间:2019-04-06 07:39:31

标签: python arrays append

将一个数组(1)附加到另一个数组(2) Update array(2)会同时更新

我将发布的脚本将显示2个不同的结果 函数-def Report_Results_Fail():-失败 函数-def Report_Results_Ok():-可以

我试图理解为什么第一次失败

def Processes_Last_Runs_Blanks_Clear(v_User_List):
    v_Blanks_Clear = [] ; v_Blanks_Clear.append("--||--")
    for i in range(len(v_User_List)):
        v_This = "-"#+" " * v_User_Len
        #v_This = v_This[0:v_User_Len]
        v_Blanks_Clear.append(v_This)
    return v_Blanks_Clear

def Active_User_List():
    # Read from file so array looks like this
    v_Users_Active = []
    v_Users_Active.append("Jeff")
    v_Users_Active.append("Kenny")
    v_Users_Active.append("Lenny")
    v_Users_Active.append("Manny")
    v_Users_Active.append("Nanny")
    return v_Users_Active

def Report_Results_Fail():
    v_Users_Active = Active_User_List()
    v_Blanks = Processes_Last_Runs_Blanks_Clear(v_Users_Active)
    v_Report = []
    v_Report.append(v_Blanks)
    v_Report[0][0] = "Process"
    v_Report[0][1] = "Users"
    for i in range(5):
        if i == len(v_Report):
            v_Report.append(v_Blanks)
        v_Report[i][1] = str(i)
    for i in range(len(v_Report)):
        print i,v_Report[i]

def Report_Results_Ok():
    v_Users_Active = Active_User_List()
    v_Report = []
    v_Report.append(Processes_Last_Runs_Blanks_Clear(v_Users_Active))
    v_Report[0][0] = "Process"
    v_Report[0][1] = "Users"
    for i in range(5):
        if i == len(v_Report):
            v_Report.append(Processes_Last_Runs_Blanks_Clear(v_Users_Active))
        v_Report[i][1] = str(i)
    for i in range(len(v_Report)):
        print i,v_Report[i]

print "Running on Imac High Sierra 10.13.6 - Python Version  2.7.10"
print "Report_Results_Fail()"
Report_Results_Fail()
print "Report_Results_Ok()"
Report_Results_Ok()

在Imac High Sierra 10.13.6上运行-Python版本2.7.10

Report_Results_Fail()

0 ['Process','4','-','-','-','-']

1 ['Process','4','-','-','-','-']

2 ['Process','4','-','-','-','-']

3 ['Process','4','-','-','-','-']

4 ['Process','4','-','-','-','-']

Report_Results_Ok()

0 ['Process','0','-','-','-','-']

1 ['-||-','1','-','-','-','-']

2 ['-||-','2','-','-','-','-']

3 ['-||-','3','-','-','-','-']

4 ['-||-','4','-','-','-','-']

0 个答案:

没有答案