scanf string in python

Karl Scalet news at yebu.de
Fri Jul 18 03:21:59 EDT 2003


lehrig schrieb:
> lehrig wrote:
> 
> 
>>I have a string which is returned by a C extension.
>>
>>mystring = '(1,2,3)'
>>
>>HOW can I read the numbers in python ?
> 
> 
> Now I have done it like this:
>   tmp = mystring[1:-1]
>   tmplist = string.split(tmp,',')
>   x = int(tmplist[0])
>   y = int(tmplist[1])
>   z = int(tmplist[2])
> 
> But there should be a more convenient solution.

exec('result='+mystring)
print result

would be shorter

Karl





More information about the Python-list mailing list