No way to convert this string to raw format for parsing
Question: I am writing a program to find the latency of the following IP:
'141.101.115.212' (A game server)

To find the latency I use the following commands:

    
    
    x = subprocess.Popen(["ping.exe", "141.101.115.212"], stdout=subprocess.PIPE)
    x = str(x.communicate()[0])
    

If I print x, I find it contains the following output:

    
    
    ...Minimum = 46ms, Maximum = 54ms, Average = 48ms\r\n'
    

So I parse the output to obtain `48ms` with the following code:

    
    
    import subprocess
    x = subprocess.Popen(["ping.exe", "141.101.115.212"], stdout=subprocess.PIPE)
    x = str(x.communicate()[0])
    lhs, rhs = x.split("Average = ")
    lhs, rhs = rhs.split("\\")
    print(lhs)
    

But I receive the following error because `rhs` is not a raw string.

    
    
    Traceback (most recent call last):
      File "C:/Users/Michael/PycharmProjects/untitled/expiriment.py", line 6, in <module>
        lhs, rhs = rhs.split("\\")
    ValueError: too many values to unpack (expected 2)
    

How do I convert the string `rhs` to a raw string?

**edit:**

As you can see by printing `rhs`, the code works after the first split, but
not the second.

    
    
    import subprocess
    x = subprocess.Popen(["ping.exe", "141.101.115.212"], stdout=subprocess.PIPE)
    x = str(x.communicate()[0])
    print(x)
    lhs, rhs = x.split("Average = ")
    print(rhs)
    lhs, rhs = rhs.split("\\")
    print (lhs)
    

**edit:**

I do infact need to cast communicate as a string.

**edit:**

The only way to split a string at a back slash with Python is to convert the
string to raw e.g.

    
    
    string = r"asdasd\asdasd"
    lhs, rhs = string.split("\\")
    print(rhs)
    


Answer: You get this error because you try to assign the result to exactly two
variables, but there are more than that.

Your string most certainly contains more than one backslash

You could get all of them with

    
    
    res = rhs.split("\\")
    

Then search res for what you need

Edit

By your comments, rhs is `57ms\r\n` before the split. This will cause split to
return 3 values, 57ms, r, n. lhs could get 57ms, rhs will get r, but n is not
handled so python panics and shows that error.

I think that what you really want to do is to remove the line break. This
should sanitize to 57ms

    
    
    res = rhs.replace('\r\n','')
    

