Re: converting lists to strings to lists

2006-04-12 Thread Dave Hansen
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

Re: converting lists to strings to lists

2006-04-12 Thread Eric Deveaud
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

Re: converting lists to strings to lists

2006-04-12 Thread bruno at modulix
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

Re: converting lists to strings to lists

2006-04-12 Thread bruno at modulix
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: >

Re: converting lists to strings to lists

2006-04-12 Thread robin
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

Re: converting lists to strings to lists

2006-04-12 Thread Peter Hansen
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

Re: converting lists to strings to lists

2006-04-12 Thread Steven D'Aprano
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

Re: converting lists to strings to lists

2006-04-12 Thread robin
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?

Re: converting lists to strings to lists

2006-04-12 Thread gry
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

Re: converting lists to strings to lists

2006-04-12 Thread Eric Deveaud
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

converting lists to strings to lists

2006-04-12 Thread robin
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