converting lists to strings to lists

Eric Deveaud edeveaud at pasteur.fr
Wed Apr 12 10:10:38 EDT 2006


robin wrote:
>  hi,
> 
>  i'm doing some udp stuff and receive strings of the form '0.870000
>  0.250000 0.790000;\n'
>  what i'd need though is a list of the form [0.870000 0.250000 0.790000]
>  i got to the [0:-3] part to obtain a string '0.870000 0.250000
>  0.790000' but i can't find a way to convert this into a list. i tried
>  eval() but this gives me the following error:

check pydoc string about split

my_string = '0.870000 0.250000 0.790000;\n'
my_list = my_string.split()
print my_list


>  and i have the same problem the other way round. e.g. i have a list
>  which i need to convert to a string in order to send it via udp.


my_new_string = ' '.join(my_list)
print my_new_string

	Eric



More information about the Python-list mailing list