Is this what you want?
data = []
for device in devices:
data.append([device])
for command in commands:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(device, username="admin", password="test")
stdin, stdout, stderr = ssh.exec_command(command)
output= stdout.read()
data[-1].append(output)
data[-1] = tuple(data[-1])
Some explanation:
what data[-1] and tuple(data[-1]) actually do
Note that data
is supposed to be a list of tuples.
data[-1]
refers to the last item of the listdata
.data[-1]
is built as a list in the inner loop. As your specified output structure ofdata
is a list of tuples, the code uses the functiontuple()
to get a tuple converted from the listdata[-1]
.