python 自定义去掉空行

  1. xml.dom.minidom中的使用
pretty_print = lambda data: '
'.join([line for line in xml.dom.minidom.parseString(data).toprettyxml(indent=' '*2).split('
') if line.strip()])

  1. list类型的使用
pretty_print = lambda data: ''.join([line for line in data if line.strip()])

my_ssh = My_ssh(ip='x.x.x.x', username='xx', password='xx')
stdin, stdout, stderr  = my_ssh.my_exec_command(" arp -a ")
stdout = stdout.readlines()

print(pretty_print(stdout))

原文地址:https://www.cnblogs.com/amize/p/13841423.html