FAQ
Hello Guys,



I'm currently working on a non-python project, and I'm trying to overcome a
task of parsing a text file into a database and/or xml file. I've managed to
find a parser example written in python, and I'm hoping to deconstruct the
code methodology a bit so I can write it in another language. So I'm hoping
someone can explain to me what these following bits of code are doing.



lines = range(data.count("\n"))

lined_data = data.split("\n")

print "Read %i vendors, now processing" % data.count("(hex)")



I've not used the split() function before, but it partly makes sense to me.
What is that piece of code doing? 'Data' is the content of the text file,
presumably the first line there is counting the number of lines in the file,
but I don't get the rest of it.



The rest of the code seems like a relatively simple set of loops, but it's
just this splitting stuff that's got me confused.



Thanks,



Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-list/attachments/20070517/a2438d85/attachment.htm

Search Discussions

  • Rishi pathak at May 17, 2007 at 9:38 am

    On 5/17/07, Robert Rawlins - Think Blue wrote:
    Hello Guys,



    I'm currently working on a non-python project, and I'm trying to overcome
    a task of parsing a text file into a database and/or xml file. I've managed
    to find a parser example written in python, and I'm hoping to deconstruct
    the code methodology a bit so I can write it in another language. So I'm
    hoping someone can explain to me what these following bits of code are
    doing.



    lines = range(data.count("\n"))

    lined_data = data.split("\n")
    eg:
    data="abc\n123\ngh\nxyz\n"
    data.split("\n") will give you an array(list in python) in the following
    manner
    ['abc', '123', 'gh', 'xyz']


    print "Read %i vendors, now processing" % data.count("(hex)")


    I've not used the split() function before, but it partly makes sense to
    me. What is that piece of code doing? 'Data' is the content of the text
    file, presumably the first line there is counting the number of lines in the
    file, but I don't get the rest of it.



    The rest of the code seems like a relatively simple set of loops, but it's
    just this splitting stuff that's got me confused.



    Thanks,



    Rob

    --
    http://mail.python.org/mailman/listinfo/python-list


    --
    Regards--
    Rishi Pathak
    National PARAM Supercomputing Facility
    Center for Development of Advanced Computing(C-DAC)
    Pune University Campus,Ganesh Khind Road
    Pune-Maharastra
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://mail.python.org/pipermail/python-list/attachments/20070517/2ae9d06a/attachment.htm
  • Michael Bentley at May 17, 2007 at 11:38 am

    On May 17, 2007, at 4:12 AM, Robert Rawlins - Think Blue wrote:
    I?m currently working on a non-python project, and I?m trying to
    overcome a task of parsing a text file into a database and/or xml
    file. I?ve managed to find a parser example written in python, and
    I?m hoping to deconstruct the code methodology a bit so I can write
    it in another language. So I?m hoping someone can explain to me
    what these following bits of code are doing.



    lines = range(data.count("\n"))

    lined_data = data.split("\n")

    print "Read %i vendors, now processing" % data.count("(hex)")



    I?ve not used the split() function before, but it partly makes
    sense to me. What is that piece of code doing? ?Data? is the
    content of the text file, presumably the first line there is
    counting the number of lines in the file, but I don?t get the rest
    of it.



    The rest of the code seems like a relatively simple set of loops,
    but it?s just this splitting stuff that?s got me confused.
    http://docs.python.org/lib/string-methods.html


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://mail.python.org/pipermail/python-list/attachments/20070517/97404cd0/attachment.html

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 17, '07 at 9:12a
activeMay 17, '07 at 11:38a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase