How do I process this?

John Gordon gordon at panix.com
Tue Mar 4 05:46:24 CET 2014


In <mailman.7690.1393905834.18130.python-list at python.org> Igor Korot <ikorot01 at gmail.com> writes:

> --047d7b6dc250a1426004f3bffd8d
> Content-Type: text/plain; charset=ISO-8859-1

> Hi, ALL,
> I have a csv file which depending on how it was produced gives 2 different
> strings as shown in the example below (test1 and test2).
> I am only interested in the first field in test1 and obviously in the whole
> string of test2.

> So, I tried to see if I can get what I want in one simple way, but failed.
> Is it possible to process the file independently?

> Thank you.

split() returns a list.  Use indexing to grab only the element you want,
like this:

    t1 = test1.split(',')[0]
    t2 = test2.split(',')[0]

-- 
John Gordon         Imagine what it must be like for a real medical doctor to
gordon at panix.com    watch 'House', or a real serial killer to watch 'Dexter'.




More information about the Python-list mailing list