<br><br><div><span class="gmail_quote">On 5/17/07, <b class="gmail_sendername">Robert Rawlins - Think Blue</b> <<a href="mailto:robert.rawlins@thinkbluemedia.co.uk">robert.rawlins@thinkbluemedia.co.uk</a>> wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-GB">
<div>
<p>Hello Guys,</p>
<p> </p>
<p>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.</p>
<p> </p>
<p style=""><span style="font-size: 9pt;">lines = range(data.count("\n"))</span></p>
<p style=""><span style="font-size: 9pt;">lined_data = data.split("\n")</span></p></div></div></blockquote><div><br>
eg:<br>
data="abc\n123\ngh\nxyz\n" <br>
data.split("\n") will give you an array(list in python) in the following manner<br>
['abc', '123', 'gh', 'xyz']<br>
<br>
</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div link="blue" vlink="purple" lang="EN-GB"><div><p><span style="font-size: 9pt;">
print
"Read %i vendors, now processing" % data.count("(hex)")</span></p>
<p><span style="font-size: 9pt;"> </span></p>
<p><span style="font-size: 9pt;">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.</span></p>
<p><span style="font-size: 9pt;"> </span></p>
<p><span style="font-size: 9pt;">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.</span></p>
<p><span style="font-size: 9pt;"> </span></p>
<p><span style="font-size: 9pt;">Thanks,</span></p>
<p><span style="font-size: 9pt;"> </span></p>
<p><span style="font-size: 9pt;">Rob</span></p>
</div>
</div>
<br>--<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div>
<br><br clear="all"><br>-- <br>Regards--<br>Rishi Pathak<br>National PARAM Supercomputing Facility<br>Center for Development of Advanced Computing(C-DAC)<br>Pune University Campus,Ganesh Khind Road<br>Pune-Maharastra