python 自定义去掉空行

  1. xml.dom.minidom中的使用
pretty_print = lambda data: '\n'.join([line for line in xml.dom.minidom.parseString(data).toprettyxml(indent=' '*2).split('\n') 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))

  1. if l[:-1].strip() 的语法
for i in ret:
      if i[:-1].strip():
            file.write(i+'\t\n')

posted @ 2020-10-19 17:20  该显示昵称已被使用了  阅读(251)  评论(0)    收藏  举报