String question

Mark Tolonen M8R-yfto6h at
Tue Jun 24 05:38:51 CEST 2008

"Andreu" <root at> wrote in message news:g3p72i$432$1 at
> Yes, ... don't ask me why, but in fact  v1,v2,v3 = str1.split()
> does not seem to work. My original problem was I forgot about
> the parenthesis as Tim point out. So I ended up converting to a
> list as in:  v = str1.split() and accessing the elements using
> v[0] v[1] is working now. Thanks.
> Andreu.

v1,v2,v3 = str1.split() will only work if there are exactly three things in 

>>> s = 'this is a test'
>>> v1,v2,v3 = s.split()
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ValueError: too many values to unpack
>>> v1,v2,v3 = s.split(' ',2)    # limit to two splits maximum
>>> v1
>>> v2
>>> v3
'a test'


More information about the Python-list mailing list