On 12 Apr 2006 06:53:23 -0700 in comp.lang.python, "robin"
<[EMAIL PROTECTED]> wrote:
>hi,
>
>i'm doing some udp stuff and receive strings of the form '0.87
>0.25 0.79;\n'
>what i'd need though is a list of the form [0.87 0.25 0.79]
>i got to the [0:-3] part to obtain a str
robin wrote:
> yo!
>
> thank you everone! here's how i finally did it:
> converting the string into a list:
>
> input = net.receiveUDPData()
> input = list(eval(input[0:-2]))
no pun intented but as you did not know how to use split and join,
please please DON'T USE eval
robin wrote:
> yo!
>
> thank you everone! here's how i finally did it:
> converting the string into a list:
>
> input = net.receiveUDPData()
> input = list(eval(input[0:-2]))
You'll run into trouble with this.
> converting the list into a string:
>
> sendout = "%.6f %.6f %.6f
robin wrote:
> thanks for your answer. split gives me a list of strings,
Of course, why should it be otherwise ?-)
More seriously : Python doesn't do much automagical conversions. Once
you've got your list of strings, you have to convert'em to floats.
> but i found a
> way to do what i want:
>
yo!
thank you everone! here's how i finally did it:
converting the string into a list:
input = net.receiveUDPData()
input = list(eval(input[0:-2]))
converting the list into a string:
sendout = "%.6f %.6f %.6f;\n" % tuple(winningvector)
maybe i'll even find a way to gene
robin wrote:
> i'm doing some udp stuff and receive strings of the form '0.87
> 0.25 0.79;\n'
> what i'd need though is a list of the form [0.87 0.25 0.79]
> i got to the [0:-3] part to obtain a string '0.87 0.25
Actually, that's already a bug. You want [0:-2] if y
On Wed, 12 Apr 2006 06:53:23 -0700, robin wrote:
> hi,
>
> i'm doing some udp stuff and receive strings of the form '0.87
> 0.25 0.79;\n'
> what i'd need though is a list of the form [0.87 0.25 0.79]
> i got to the [0:-3] part to obtain a string '0.87 0.25
> 0.7900
thanks for your answer. split gives me a list of strings, but i found a
way to do what i want:
input='0.1, 0.2, 0.3;\n'
input = list(eval(input[0:-2]))
print input
> [0.10001, 0.20001, 0.2]
this does fine... but now, how do i convert this list to a string?
Read about string split and join. E.g.:
l = '0.87 0.25 0.79'
floatlist = [float(s) for s in l.split()]
In the other direction:
floatlist = [0.87, 0.25, 0.79004]
outstring = ' '.join(floatlist)
If you need to control the precision(i.e. suppress the 4), read
about
the s
robin wrote:
> hi,
>
> i'm doing some udp stuff and receive strings of the form '0.87
> 0.25 0.79;\n'
> what i'd need though is a list of the form [0.87 0.25 0.79]
> i got to the [0:-3] part to obtain a string '0.87 0.25
> 0.79' but i can't find a way to c
hi,
i'm doing some udp stuff and receive strings of the form '0.87
0.25 0.79;\n'
what i'd need though is a list of the form [0.87 0.25 0.79]
i got to the [0:-3] part to obtain a string '0.87 0.25
0.79' but i can't find a way to convert this into a list. i tried
11 matches
Mail list logo