Code Explanation
Michael Bentley
michael at jedimindworks.com
Thu May 17 07:38:52 EDT 2007
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>
More information about the Python-list
mailing list