Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Split string data have ","

Reply
Thread Tools

Split string data have ","

 
 
moonhkt
Guest
Posts: n/a
 
      01-29-2013
Hi All

Python 2.6.2 on AIX 5.3
How to using split o

>>> 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
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      01-29-2013
On Jan 29, 2013 9:05 AM, "moonhkt" <> wrote:
>
> Hi All
>
> Python 2.6.2 on AIX 5.3
> How to using split o
>
> >>> 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


Try the csv module or the shlex module.

 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      01-29-2013
On Tue, 29 moonhkt <> 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



 
Reply With Quote
 
moonhkt
Guest
Posts: n/a
 
      01-30-2013
On Jan 30, 1:08*am, Chris Rebert <c...@rebertia.com> wrote:
> On Jan 29, 2013 9:05 AM, "moonhkt" <moon...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
> > Hi All

>
> > Python 2.6.2 on AIX 5.3
> > How to using split o

>
> > >>> 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

>
> Try the csv module or the shlex module.


Thank a lot, Using csv is good for me.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Split string first data have ", moonhkt Python 1 01-29-2013 05:07 PM
How to use String.split to split a mixed encoding string(partencoded in gbk, part encoded in utf-8) Stanley Xu Ruby 2 03-23-2011 02:06 PM
String#split(/\s+/) vs. String#split(/(\s+)/) Sam Kong Ruby 5 08-12-2006 07:59 PM
How can I split database results with ExecuteReader and Split? needin4mation@gmail.com ASP .Net 2 05-05-2006 10:36 PM
Small inconsistency between string.split and "".split Carlos Ribeiro Python 11 09-17-2004 05:57 PM



Advertisments