<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Simple substring counting script in Python</title>
	<atom:link href="http://bogdan.org.ua/2006/06/21/simple-substring-counting-script-in-python.html/feed" rel="self" type="application/rss+xml" />
	<link>http://bogdan.org.ua/2006/06/21/simple-substring-counting-script-in-python.html</link>
	<description>Tiny bits of bioinformatics, [web-]programming etc</description>
	<lastBuildDate>Sun, 14 Mar 2010 08:55:31 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Bogdan</title>
		<link>http://bogdan.org.ua/2006/06/21/simple-substring-counting-script-in-python.html/comment-page-1#comment-103355</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Thu, 07 Jan 2010 16:25:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.bogdan.org.ua/blog/2006/06/21/simple-substring-counting-script-in-python.html#comment-103355</guid>
		<description>Nice, thanks.</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Nice, thanks.<!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pete</title>
		<link>http://bogdan.org.ua/2006/06/21/simple-substring-counting-script-in-python.html/comment-page-1#comment-103354</link>
		<dc:creator>pete</dc:creator>
		<pubDate>Thu, 07 Jan 2010 15:26:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.bogdan.org.ua/blog/2006/06/21/simple-substring-counting-script-in-python.html#comment-103354</guid>
		<description>&lt;pre&gt;&lt;code&gt;
def getSubStringPositionsList(str=None, subStr=None):
    l=[]
    posCount = 0
    while str:
        pos = str.find(subStr)
        if pos != -1:
            l.append(pos + posCount)
            str = str[pos + len(subStr):]
            posCount += pos + len(subStr)
        else:
            break
    return l

def getSubStringCount(str=None, subStr=None):
    return len(getSubStringPositionsList(str, subStr))
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->
<pre><code>
def getSubStringPositionsList(str=None, subStr=None):
    l=[]
    posCount = 0
    while str:
        pos = str.find(subStr)
        if pos != -1:
            l.append(pos + posCount)
            str = str[pos + len(subStr):]
            posCount += pos + len(subStr)
        else:
            break
    return l

def getSubStringCount(str=None, subStr=None):
    return len(getSubStringPositionsList(str, subStr))
</code></pre>
<p><!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://bogdan.org.ua/2006/06/21/simple-substring-counting-script-in-python.html/comment-page-1#comment-102552</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Mon, 12 Oct 2009 09:38:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.bogdan.org.ua/blog/2006/06/21/simple-substring-counting-script-in-python.html#comment-102552</guid>
		<description>Thanks for the contribution!

* please note, that the script listed is 3+ years old; something has definitely changed in Python since then
* your options parser is definitely less flexible (and less verbose to the end-user)
* your main loop is indeed several lines shorter, but mostly thanks to omitting open() and file.close() with while() - imported from __future__, as well as not using the &#039;--verbose&#039; option processing to dump extra data to the terminal

Overall, I find your submission definitely useful, but not actually as short and simple as you implied with &quot;That&#039;s not simple :)&quot; :)</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->Thanks for the contribution!</p>
<p>* please note, that the script listed is 3+ years old; something has definitely changed in Python since then<br />
* your options parser is definitely less flexible (and less verbose to the end-user)<br />
* your main loop is indeed several lines shorter, but mostly thanks to omitting open() and file.close() with while() &#8211; imported from __future__, as well as not using the &#8216;&#8211;verbose&#8217; option processing to dump extra data to the terminal</p>
<p>Overall, I find your submission definitely useful, but not actually as short and simple as you implied with &#8220;That&#8217;s not simple <img src='http://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8221; <img src='http://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> <!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spiderlama</title>
		<link>http://bogdan.org.ua/2006/06/21/simple-substring-counting-script-in-python.html/comment-page-1#comment-102550</link>
		<dc:creator>spiderlama</dc:creator>
		<pubDate>Mon, 12 Oct 2009 04:56:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.bogdan.org.ua/blog/2006/06/21/simple-substring-counting-script-in-python.html#comment-102550</guid>
		<description>That&#039;s not simple :P

&lt;pre&gt;&lt;code&gt;
from __future__ import with_statement
import sys

if __name__ == &#039;__main__&#039;:
    assert len(sys.argv) == 3, &#039;invalid arguments. usage: file str&#039;

    filePath = sys.argv[1]
    substr = sys.argv[2]
    linesFound = 0
    substrFound = 0
    
    with open(filePath) as f:
        for lineIndex, lineString in enumerate(f):
            if lineString.find(substr) != -1:
                linesFound += 1
                substrFound += lineString.count(substr)
                print filePath + &#039;:&#039; + str(lineIndex) + &#039;\t&#039; + \
                    lineString.rstrip(&#039;\r\n&#039;)

        print &#039;Lines read from file:&#039;, lineIndex + 2
        print &#039;Lines with substring found:&#039;, linesFound
        print &#039;Total substrings detected:&#039;, substrFound
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p><!-- google_ad_section_start -->That&#8217;s not simple <img src='http://bogdan.org.ua/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<pre><code>
from __future__ import with_statement
import sys

if __name__ == '__main__':
    assert len(sys.argv) == 3, 'invalid arguments. usage: file str'

    filePath = sys.argv[1]
    substr = sys.argv[2]
    linesFound = 0
    substrFound = 0

    with open(filePath) as f:
        for lineIndex, lineString in enumerate(f):
            if lineString.find(substr) != -1:
                linesFound += 1
                substrFound += lineString.count(substr)
                print filePath + ':' + str(lineIndex) + '\t' + \
                    lineString.rstrip('\r\n')

        print 'Lines read from file:', lineIndex + 2
        print 'Lines with substring found:', linesFound
        print 'Total substrings detected:', substrFound
</code></pre>
<p><!-- google_ad_section_end --></p>
]]></content:encoded>
	</item>
</channel>
</rss>
