Getting Distance From Raspberry Pi

Try with these changes:

#DWM Serial Parser by Brian H. | Updated 3/6/19
import serial
import time
import datetime


DWM=serial.Serial(port="/dev/serial0", baudrate=115200)
print("Connected to " +DWM.name)
DWM.write("\r\r".encode())
time.sleep(1)
DWM.write("lec\r".encode())
time.sleep(1)
while True:
    try:
        line=DWM.readline()
        if(line):
            parse=line.decode().split(",")
            if parse[0]=="DIST":
                pos_AN0=(parse[parse.index("AN0")+2],parse[parse.index("AN0")+3],parse[parse.index("AN0")+4])
                dist_AN0=parse[parse.index("AN0")+5]
                print(datetime.datetime.now().strftime("%H:%M:%S"),pos_AN0,":",dist_AN0)
            else:
                print("Distance not calculated: ",line.decode())
    except Exception as ex:
        print(ex)
        break
DWM.write("\r".encode())
DWM.close()