Split string data have ","

Discussion in 'Python' started by moonhkt, Jan 29, 2013.

  1. moonhkt

    moonhkt Guest

    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
    moonhkt, Jan 29, 2013
    #1
    1. Advertising

  2. moonhkt

    Chris Rebert Guest

    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.
    Chris Rebert, Jan 29, 2013
    #2
    1. Advertising

  3. moonhkt

    Tim Chase Guest

    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
    Tim Chase, Jan 29, 2013
    #3
  4. moonhkt

    moonhkt Guest

    On Jan 30, 1:08 am, Chris Rebert <> wrote:
    > 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.


    Thank a lot, Using csv is good for me.
    moonhkt, Jan 30, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    453
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    686
    Alex Martelli
    Sep 17, 2004
  3. Sam Kong
    Replies:
    5
    Views:
    227
    Rick DeNatale
    Aug 12, 2006
  4. Stanley Xu
    Replies:
    2
    Views:
    587
    Stanley Xu
    Mar 23, 2011
  5. moonhkt

    Split string first data have ",

    moonhkt, Jan 29, 2013, in forum: Python
    Replies:
    1
    Views:
    126
    Nick Cash
    Jan 29, 2013
Loading...

Share This Page