Get read of ['\n'] in python3 with paramiko
Question: I've just started to do some monitoring tool in python3 and I wondered, if I
can get 'clear' number output through ssh. I've made some script:

    
    
    import os
    import paramiko
    
    command = 'w|grep \"load average\"|grep -v grep|awk {\'print ($10+$11+$12)/3*100\'};'
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy())
    ssh.connect('10.123.222.233', username='xxx', password='xxx')
    stdin, stdout, stderr = ssh.exec_command(command)
    print (stdout.readlines())
    ssh.close()
    

It works fine, except output is:

    
    
    ['22.3333\n']
    

How can I get rid of " [' " and " \n'] " and just get the clear number value?

How to get the result as I see it just in putty?


Answer: `.readlines()` returns a _list_ of separate lines. In your case there is just
one line, you can just extract it by indexing the list, then strip of the
whitespace at the end:

    
    
    firstline = stdout.readlines()[0].rstrip()
    

This is still a string, however. If you expected _numbers_ , you'd have to
convert the string to a `float()`. Since your command line will only ever
return **one** line, you may as well just use `.read()` and convert that
straight up (no need to strip, as `float()` is tolerant of trailing and
leading whitespace):

    
    
    result = float(stdout.read())
    

