[Tutor] Unpacking a Tuple - Can It Be Done with a CSV Line?

Doug Stanfield DOUGS@oceanic.com
Tue, 30 Jan 2001 15:31:28 -1000

What you're looking for is the string functions.  There have been some
changes in this area between Python 1.5.2 and 2.0.  I'm most familiar with
1.5.2 so thats what I give you here:

[dougs@lawehana dougs]$ python
Python 1.5.2 (#1, Apr 18 1999, 16:03:16)  [GCC pgcc-2.91.60 19981201
(egcs-1.1.1  on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import string
>>> line = 'value1, value2, value3, value4'
>>> values = string.split(line,',')
>>> print values
['value1', ' value2', ' value3', ' value4']


-----Original Message-----
From: Seelinger, Bruce [mailto:bseelinger@neteffectcorp.com]
Sent: Tuesday, January 30, 2001 11:50 AM
To: 'tutor@python.org'
Subject: [Tutor] Unpacking a Tuple - Can It Be Done with a CSV Line?

I am writing a script which opens a file which consists of comma separated
entries similar to the example below: 
value1, value2, value3, value4,  etc. etc. 
The above line is read and assigned to a variable.  At that point I was
hoping it could be treated as a tuple or sequence of values.  Unfortunately,
the variable treats the entire line as a single string instead of separate
values between the commas.  Is there any way to have the line act as a tuple
which can be unpacked?  Essentially, I want to extract values from a comma
separated list of values from each line.
I am relatively new to Python and the only other language I have extensive
programming with is VMS's DCL. 
Can anyone help? 
Thanks in advance for any help! 
Bruce Seelinger