tags:

views:

49

answers:

1

I have a program that grabs some data through ssh using paramiko:

ssh = paramiko.SSHClient()

ssh.connect(main.Server_IP, username=main.Username, password=main.Password)

ssh_stdin_host, ssh_stdout_host, ssh_stderr_host =ssh_session.exec_command(setting.GetHostData)

I would like to remove the first 4 lines from ssh_stdout_host. I've tried using StringIO to use readlines like this:

output = StringIO("".join(ssh_stdout_host))
data_all = output.readlines()

But I'm lost after this. What would be a good approach? Im using python 2.6.5. Thanks.

+1  A: 

readlines provides all the data

allLines = [line for line in stdout.readlines()]
data_no_firstfour = "\n".join(allLines[4:])
pyfunc
Google for "python list slice syntax" for all of the cool stuff you can do to lists this way.
Powertieke
Also I have used Paramiko and I was not sure if stdout.readlines() returns an iterator or the complete list of lines. The first line of the above code would be superflous if it returns a list. But I guess this makes sure that the code won't fault.
pyfunc
Thanks! Just what I was looking for.
Ping Pengũin