Split string data have ","

Tim Chase python.list at tim.thechases.com
Tue Jan 29 12:14:10 EST 2013


On Tue, 29 moonhkt <moonhkt at gmail.com> wrote:
> >>> y = '"abc.p,zip.p",a,b'
> >>> print y
> "abc.p,zip.p",a,b
> >>>
> 
> >>> k= y.split(",")
> >>> print k[0]
> "abc.p
> >>>
> 
> Need Result, First element is
> abc.p,zip.p

The csv module should handle this nicely:

  >>> import csv
  >>> y = '"abc.p,zip.p",a,b'
  >>> print y
  "abc.p,zip.p",a,b
  >>> r = csv.reader([y])
  >>> print r.next()
  ['abc.p,zip.p', 'a', 'b']

-tkc






More information about the Python-list mailing list