[Tutor] a beginning question
alan.gauld at btinternet.com
Sat Feb 20 05:33:51 EST 2016
On 20/02/16 09:15, Paul Z wrote:
> Hi all,
> I receive the string messages from my Mobile via UDP as below:
> A, 0.1, 0.6, 0.7
> B, 0.2, 0.3, 0.8
I think we need a bit more detail.
How do you receive these messages? UDP requires some
kind of receiving service, so what is it that is
receiving these messages? Is it your python program?
Or is it some other bit of software?
Having received these strings what happens?
Are they stored in a variable? In a file? where?
> I want to arrange them to two array as below:
> a = (0.1, 0.6, 0.7)
> b = (0.2, 0.3, 0.8)
What you've shown would be tuples in Python, not
arrays. We need to be precise about data types.
Do you want the data in a list, a tuple, an array?
Do you understand the differences?
Now, to try to answer your question based on the
most optimistic set of assumptions:
ie. You are receiving the messages in your python code
and storing them as string variables called s1
and s2 and you want the result to be a list of floats.
a = [float(n) for n in s1.split(',')]
b = [float(n) for n in s2.split(',')]
But I suspect that I'm being overly optimistic...
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor