Re: convert a string to tuple
- From: Marc 'BlackJack' Rintsch <bj_666@xxxxxxx>
- Date: Tue, 31 May 2005 22:50:34 +0200
In <1117570449.887422.225670@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, querypk wrote:
> how do I convert
> b is a string b = '(1,2,3,4)' to b = (1,2,3,4)
In [1]: b = '(1,2,3,4)'
In [2]: b[1:-1]
Out[2]: '1,2,3,4'
In [3]: b[1:-1].split(',')
Out[3]: ['1', '2', '3', '4']
In [4]: tuple(b[1:-1].split(','))
Out[4]: ('1', '2', '3', '4')
Ooops, you wanted ints in there:
In [5]: tuple(map(int, b[1:-1].split(',')))
Out[5]: (1, 2, 3, 4)
Ciao,
Marc 'BlackJack' Rintsch
.
- References:
- convert a string to tuple
- From: querypk
- convert a string to tuple
- Prev by Date: Re: convert a string to tuple
- Next by Date: Re: convert a string to tuple
- Previous by thread: Re: convert a string to tuple
- Next by thread: running tkinter
- Index(es):
Relevant Pages
|