在下面的代码中,每个x具有y的9个值。 我想要new_gamesplyed = [x,y1,y2,y3,y4,y5,y6,y7,y8,y9]。 但是在“差异”列表中,所有292个值都被立即存储。
[/home/VB] >cat common_functions.sh
#!/bin/sh
# the next line restarts using expect \
exec expect "$0" "$@"
proc wait_for_prompt {prompt {s 90}} {
puts "wait_for_prompt calling ..."
set timeout $s
expect {
$prompt {}
}
}
proc handle_login { args } {
puts "handle_login calling ..."
expect {
":~#" {puts "handle_login accessed to remote"}
}
}
[/home/VB] >cat test_expect_with_source.sh
#!/bin/sh
# the next line restarts using expect \
exec expect "$0" "$@"
source common_functions.sh
set remote_ip [lindex $argv 0]
set remote_remote_host [lindex $argv 1]
set timeout 5
puts "test_expect_with_source calling ..."
log_user 1
spawn ssh -o ConnectTimeout=3 root@$remote_ip
handle_login
puts "zone to access second remote"
after 1500
send "ssh $remote_remote_host\r"
wait_for_prompt ":*#"
...
[/home/VB] >./test_expect_with_source.sh 192.168.100.10 TESTING_MACHINE.TEST.HOST
test_expect_with_source calling ...
spawn ssh -o ConnectTimeout=3 root@192.168.100.10
handle_login calling ...
Last login: Wed Oct 23 07:42:25 2019 from 192.168.100.20
VB_machine:~# handle_login accessed to remote
zone to access second remote
wait_for_prompt calling ... (confuse between this line)
ssh TESTING_MACHINE.TEST.HOST (and this line)
...
答案 0 :(得分:0)
您在整个代码段中都使用了相同的difference
变量,因此也难怪它存储了append
传递给它的所有值
如果我正确理解,您需要在主循环中的某些语句之间“重置”容器。因此,我建议每次在主循环语句开始时重新初始化存储桶集合。示例:
for x in range(len(df_gamesplayed)):
d_temp = [] # <--------- reset it here ----------
for y in range (1, col_count):
diff = abs(df_gamesplayed.iloc[x, y] - df_gamesplayed.iloc[x, y + 1])
d_temp.append(diff)
new_gamesplayed.append([df_gamesplayed.iloc[x, 0], d_temp])