<?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"
	>
<channel>
	<title>Comments on: Python Recipe: Open a file, read it, print each line matching a search.</title>
	<atom:link href="http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/</link>
	<description>life it ain't real funky, 'less it's got that pop...
</description>
	<pubDate>Tue, 06 Jan 2009 22:06:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: M218</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-125787</link>
		<dc:creator>M218</dc:creator>
		<pubDate>Mon, 08 Sep 2008 13:37:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-125787</guid>
		<description>Using Unix (Linux or Mac) and never heard of grep?
try
grep -i love _your_file
or
grep '\(l\&#124;L\)ove' _your_file
or
egrep '(l&#124;L)ove' _your_file</description>
		<content:encoded><![CDATA[<p>Using Unix (Linux or Mac) and never heard of grep?<br />
try<br />
grep -i love _your_file<br />
or<br />
grep &#8216;\(l\|L\)ove&#8217; _your_file<br />
or<br />
egrep &#8216;(l|L)ove&#8217; _your_file</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: palewire / Python Recipe: Connect to MySQL database, execute a query, print the results.</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-76058</link>
		<dc:creator>palewire / Python Recipe: Connect to MySQL database, execute a query, print the results.</dc:creator>
		<pubDate>Sat, 26 Apr 2008 17:29:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-76058</guid>
		<description>[...] in a variable called fields, which we&#8217;ll print out using one of the simple loops I covered in previous recipes, pulling out the first and second fields (name and datatype) for my table. You could take a look [...]</description>
		<content:encoded><![CDATA[<p>[...] in a variable called fields, which we&#8217;ll print out using one of the simple loops I covered in previous recipes, pulling out the first and second fields (name and datatype) for my table. You could take a look [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: palewire / Python Recipe: Grab a page, scrape a table, download a file.</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-74623</link>
		<dc:creator>palewire / Python Recipe: Grab a page, scrape a table, download a file.</dc:creator>
		<pubDate>Sun, 20 Apr 2008 20:54:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-74623</guid>
		<description>[...] a change of pace. Our first few lessons focused on how you can use Python to goof with a bunch of local files. This time [...]</description>
		<content:encoded><![CDATA[<p>[...] a change of pace. Our first few lessons focused on how you can use Python to goof with a bunch of local files. This time [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-73088</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 15 Apr 2008 17:46:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-73088</guid>
		<description>oh, yeah, the code viewer works great, if I cut and paste code from it directly into textmate (editor i'm using), no ascii problems. I did run into some problems when i mixed code from your code viewer with code from web pages, something i shouldn't have done.

thanks for the bash links and the explanation on "env" ...  i'm also a firm believer in superstition, as is our buddy &lt;a href="http://video1.washingtontimes.com/joecurl/2008/04/mccain_triskaidekaphobic_1.html" rel="nofollow"&gt;John McCain&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>oh, yeah, the code viewer works great, if I cut and paste code from it directly into textmate (editor i&#8217;m using), no ascii problems. I did run into some problems when i mixed code from your code viewer with code from web pages, something i shouldn&#8217;t have done.</p>
<p>thanks for the bash links and the explanation on &#8220;env&#8221; &#8230;  i&#8217;m also a firm believer in superstition, as is our buddy <a href="http://video1.washingtontimes.com/joecurl/2008/04/mccain_triskaidekaphobic_1.html" rel="nofollow" onclick="javascript:pageTracker._trackPageview ('/outbound/video1.washingtontimes.com');">John McCain</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: palewire</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-73064</link>
		<dc:creator>palewire</dc:creator>
		<pubDate>Tue, 15 Apr 2008 15:13:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-73064</guid>
		<description>Okay. I'm not sure I follow, but it sounds like &lt;em&gt;maybe&lt;/em&gt; the new code formatting is working for you.

I assume the Mac terminal must have some sort of encoding scheme (Isn't it in the display preferences or something?), but I really don't know how it works. &lt;a href="http://www.rift.dk/news.php?item.7.6" rel="nofollow"&gt;These&lt;/a&gt; &lt;a href="http://desp.night.pl/terminal.html" rel="nofollow"&gt;guys&lt;/a&gt; claim to be on top of it, for whatever that's worth.

As far as python's "shebang" goes, you're right, "env" is the home of all your environment variables, which includes the PATH varible that would show the way to your "python" command and interpreter. Try typing "env" into your bash sometime and you'll see what I mean. It also looks like Wikipedia has &lt;a href="http://en.wikipedia.org/wiki/Environment_variable" rel="nofollow"&gt;a helpful entry&lt;/a&gt; on the topic.

I'm a long way from an expert on this stuff, but I'm sure that on many systems you could happily substitute...

&lt;pre lang="Python"&gt;
#!/usr/bin/python&lt;/pre&gt;

... or whatever the direct path is to your python interpreter's binary file and it would still work fine. In fact, I bet that, depending on how you execute the file...

&lt;pre lang="Python"&gt;
#!python
&lt;/pre&gt;

...might even work. 

Frankly, the only reason I use /usr/bin/env is superstition,  it's the convention I was taught when I started. My guess for why it's better: I think it would probably still work if my python installation was not at /usr/bin/python, but still somewhere else on the PATH. If you explictly state the location of python, then I suppose it would probably stop working if you moved to a system where it was someplace else. For example, what if you're running Mac OSX and you install Python or Ruby or whatever using Fink or MacPorts or whatever and it puts it in some weird location.</description>
		<content:encoded><![CDATA[<p>Okay. I&#8217;m not sure I follow, but it sounds like <em>maybe</em> the new code formatting is working for you.</p>
<p>I assume the Mac terminal must have some sort of encoding scheme (Isn&#8217;t it in the display preferences or something?), but I really don&#8217;t know how it works. <a href="http://www.rift.dk/news.php?item.7.6" rel="nofollow" onclick="javascript:pageTracker._trackPageview ('/outbound/www.rift.dk');">These</a> <a href="http://desp.night.pl/terminal.html" rel="nofollow" onclick="javascript:pageTracker._trackPageview ('/outbound/desp.night.pl');">guys</a> claim to be on top of it, for whatever that&#8217;s worth.</p>
<p>As far as python&#8217;s &#8220;shebang&#8221; goes, you&#8217;re right, &#8220;env&#8221; is the home of all your environment variables, which includes the PATH varible that would show the way to your &#8220;python&#8221; command and interpreter. Try typing &#8220;env&#8221; into your bash sometime and you&#8217;ll see what I mean. It also looks like Wikipedia has <a href="http://en.wikipedia.org/wiki/Environment_variable" rel="nofollow" onclick="javascript:pageTracker._trackPageview ('/outbound/en.wikipedia.org');">a helpful entry</a> on the topic.</p>
<p>I&#8217;m a long way from an expert on this stuff, but I&#8217;m sure that on many systems you could happily substitute&#8230;</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('931');">[<span id="931_symbol">-</span>]</a></span><span class="codebox_left"><span id="l93code1"><a href="javascript:;" onclick="javascript:showCodeTxt('93code1'); return false;">View Code</a> PYTHON</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="931"><td class="code" id="93code1"><pre class="python"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span></pre></td></tr></table></div>

<p>&#8230; or whatever the direct path is to your python interpreter&#8217;s binary file and it would still work fine. In fact, I bet that, depending on how you execute the file&#8230;</p>

<div class="wp_codebox_msgheader"><span class="codebox_right"><a href="javascript:;" onclick="toggle_collapse('932');">[<span id="932_symbol">-</span>]</a></span><span class="codebox_left"><span id="l93code2"><a href="javascript:;" onclick="javascript:showCodeTxt('93code2'); return false;">View Code</a> PYTHON</span></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="932"><td class="code" id="93code2"><pre class="python"><span style="color: #808080; font-style: italic;">#!python</span></pre></td></tr></table></div>

<p>&#8230;might even work. </p>
<p>Frankly, the only reason I use /usr/bin/env is superstition,  it&#8217;s the convention I was taught when I started. My guess for why it&#8217;s better: I think it would probably still work if my python installation was not at /usr/bin/python, but still somewhere else on the PATH. If you explictly state the location of python, then I suppose it would probably stop working if you moved to a system where it was someplace else. For example, what if you&#8217;re running Mac OSX and you install Python or Ruby or whatever using Fink or MacPorts or whatever and it puts it in some weird location.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72975</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 15 Apr 2008 08:42:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72975</guid>
		<description>ignore that last comment, mixing utf-8 and ascii not a good idea</description>
		<content:encoded><![CDATA[<p>ignore that last comment, mixing utf-8 and ascii not a good idea</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72973</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 15 Apr 2008 08:35:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72973</guid>
		<description>interesting trivia: when i cut utf-8 and paste it into the python script as a comment, has no problem. just actual code</description>
		<content:encoded><![CDATA[<p>interesting trivia: when i cut utf-8 and paste it into the python script as a comment, has no problem. just actual code</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72967</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 15 Apr 2008 07:47:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72967</guid>
		<description>ok, the view code thing kicks ass, looks like javascript only? 

Tried it twice on new &lt;a href="http://www.palewire.com/2008/04/14/python-recipe-read-a-file-search-for-a-pattern-print-your-matches/" rel="nofollow"&gt;recipe&lt;/a&gt;. First, cut-and-pasted formatted text from the blog page, got non-ascii error, halted. Then ran code cut-and-pasted from popup plain text "view code" window, ran great. 

When it comes to copying-and-pasting, does Bash (in Terminal) also care if the text is ascii or utf or iso or whatever?

The whole topper thing brings up a novice recurring question for me: why is python's declaration path:

$ /usr/bin/env python

and not just 

$ /usr/bin/

which has the python files. is env some kind of pointer file that every system has, sort of a preferences file?</description>
		<content:encoded><![CDATA[<p>ok, the view code thing kicks ass, looks like javascript only? </p>
<p>Tried it twice on new <a href="http://www.palewire.com/2008/04/14/python-recipe-read-a-file-search-for-a-pattern-print-your-matches/" rel="nofollow">recipe</a>. First, cut-and-pasted formatted text from the blog page, got non-ascii error, halted. Then ran code cut-and-pasted from popup plain text &#8220;view code&#8221; window, ran great. </p>
<p>When it comes to copying-and-pasting, does Bash (in Terminal) also care if the text is ascii or utf or iso or whatever?</p>
<p>The whole topper thing brings up a novice recurring question for me: why is python&#8217;s declaration path:</p>
<p>$ /usr/bin/env python</p>
<p>and not just </p>
<p>$ /usr/bin/</p>
<p>which has the python files. is env some kind of pointer file that every system has, sort of a preferences file?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: palewire / Python Recipe: Read a file, search for a pattern, print your matches.</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72943</link>
		<dc:creator>palewire / Python Recipe: Read a file, search for a pattern, print your matches.</dc:creator>
		<pubDate>Tue, 15 Apr 2008 05:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72943</guid>
		<description>[...] first two recipes focused primarily on how to open one or more files and loop through them line by line. [...]</description>
		<content:encoded><![CDATA[<p>[...] first two recipes focused primarily on how to open one or more files and loop through them line by line. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: palewire</title>
		<link>http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72367</link>
		<dc:creator>palewire</dc:creator>
		<pubDate>Sun, 13 Apr 2008 08:25:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.palewire.com/2008/04/05/python-recipe-open-a-file-read-through-it-print-each-line-matching-a-search-term/#comment-72367</guid>
		<description>Hey Tom,

I put in some time today dressing up little things on the blog's infrastructure. One thing I tried to do was wrap in the code formatting style you see above. Are the copy and pastes working for you now?</description>
		<content:encoded><![CDATA[<p>Hey Tom,</p>
<p>I put in some time today dressing up little things on the blog&#8217;s infrastructure. One thing I tried to do was wrap in the code formatting style you see above. Are the copy and pastes working for you now?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.622 seconds -->
