Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with delimiters
#1
Hello everyone
I am quite stuck. i am trying to get a message from a TCP communication protocol, this message is converted in a list of strings and then into a list of float, The thing is that im getting an error because of the delimiters.
<the message is dynamic and it has this form:
message = 0.2081006,0.0000000,0.0000000,0.2081006,0.0000000,0.0000000,0.2081006,0.0000000,0.0000000*
i want to get everything behind the '*'
here is my code
while True:

    message = conn.recv(BUFFER_SIZE)
    if not message:
        break
                
    t1 = time.time()
    message = message.decode("utf-8")
    print("Raw message: {}".format(message))


    data = list(message.split(","))
    print("Data Size:{} ".format(len(data)))
    

    
    MyNewData = []
    for item in data:
        MyNewData.append(float(item))
    print("The new list: {}".format(MyNewData))

        
    print("Size:{} ".format(len(data)))
    if len(MyNewData) < 9:
        continue


    DataX = MyNewData[0:3]
    DataY = MyNewData[3:6]
    DataZ = MyNewData[6:9]
This the ouput and error
Output:
Raw message: 0.2081006,0.0000000,0.0000000,0.2081006,0.0000000,0.0000000,0.2081006,0.0000000,0.0000000*
expected output should be like this
message: 0.2081006,0.0000000,0.0000000,0.2081006,0.0000000,0.0000000,0.2081006,0.0000000,0.0000000
Error:
File "lstm_server_3.py", line 158, in <module> MyNewData.append(float(item)) ValueError: could not convert string to float: '0.0000000*'
The i changed the code into this
while True:

    message = conn.recv(BUFFER_SIZE)
    if not message:
        break
                
    t1 = time.time()
    message = message.decode("utf-8")
    print("Raw message: {}".format(message))


    data = list(message.split(","))
    print("Data Size:{} ".format(len(data)))
    

        


  
    MyLastString = data[-1]

    
    result2 = MyLastString.find('*')
    if result2 > 0:
        MyLastString = MyLastString[0:result2]

    data[len(data)-1] = MyLastString
    
    MyNewData = []
    for item in data:
        MyNewData.append(float(item))
    print("The new list: {}".format(MyNewData))

        
    print("Size:{} ".format(len(data)))
    if len(MyNewData) < 9:
        continue


    DataX = MyNewData[0:3]
    DataY = MyNewData[3:6]
    DataZ = MyNewData[6:9]
Now the error is in the first position of the list. Also it seems that some part of the last element is in the first element
Output:
message: 35*0.2593872,0.0000000,-5.0712390,0.2593872,0.0000000,-0.4532299,0.2593872,0.0000000,-0.10
so my expected output should be like this
message: 0.2593872,0.0000000,-5.0712390,0.2593872,0.0000000,-0.4532299,0.2593872,0.0000000,-0.1035

Error:
File "lstm_server_3.py", line 158, in <module> MyNewData.append(float(item)) ValueError: could not convert string to float: '35*0.2593872'
Reply


Messages In This Thread
Problem with delimiters - by johnprada - Jan-28-2020, 04:39 PM
RE: Problem with delimiters - by buran - Jan-28-2020, 04:55 PM
RE: Problem with delimiters - by johnprada - Jan-29-2020, 02:00 AM
RE: Problem with delimiters - by buran - Jan-29-2020, 04:15 AM
RE: Problem with delimiters - by buran - Jan-29-2020, 04:16 AM
RE: Problem with delimiters - by DeaD_EyE - Jan-29-2020, 10:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delimiters - How to skip some html tags from being translate Melcu54 0 1,652 May-26-2021, 06:21 AM
Last Post: Melcu54
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,348 Apr-11-2021, 11:03 PM
Last Post: lastyle
  Split string between two different delimiters, with exceptions DreamingInsanity 2 2,018 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  Problem with delimiters johnprada 1 1,976 Jan-28-2020, 04:27 PM
Last Post: buran
  splitting a string with 2 different delimiters Skaperen 4 2,715 Dec-30-2019, 04:49 AM
Last Post: BamBi25
  Split a long string into other strings with no delimiters/characters krewlaz 4 2,774 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  re.split multiple delimiters problem gw1500se 2 3,614 Jun-24-2019, 02:43 PM
Last Post: gw1500se
  Finding nested delimiters wfsteadman 4 3,142 Jan-22-2018, 07:23 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020