<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ShinyLight Development &#187; Python</title>
	<atom:link href="http://www.shinylight.com/category/languages/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shinylight.com</link>
	<description>Web Development and Other Goodness in the World of a Software Engineer.</description>
	<lastBuildDate>Mon, 07 Jun 2010 03:02:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generate Junk Files</title>
		<link>http://www.shinylight.com/2010/04/24/generate-junk-files/</link>
		<comments>http://www.shinylight.com/2010/04/24/generate-junk-files/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 05:00:27 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=942</guid>
		<description><![CDATA[The other day I was testing benchmarks for a delete script. I needed to create files with various file sizes. More specific, 1,000,000 files with 5K per file. A while ago I found this great snippet on StackOverflow to generate a junk random string:

junk =  &#40;&#40;&#34;%%0%dX&#34; % &#40;junk_len * 2&#41;&#41; % random.getrandbits&#40;junk_len * 8&#41;&#41;.decode&#40;&#34;hex&#34;&#41;

I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was testing benchmarks for a delete script. I needed to create files with various file sizes. More specific, 1,000,000 files with 5K per file. A while ago I found this great snippet on <a href="http://stackoverflow.com/questions/785058/random-strings-in-python-2-6-is-this-ok">StackOverflow to generate a junk random string</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">junk =  <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%%0%dX&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">random</span>.<span style="color: black;">getrandbits</span><span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>I&#8217;ve wrapped that around to make a utility function and snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">random</span>, <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This tool takes 3 parameters</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;">#   testing &lt;directory to put files in&gt; &lt;how many files&gt; &lt;size of each file in bytes&gt;</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Example:</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;">#   testing dan 100 500</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> createLocalDirectory<span style="color: black;">&#40;</span> directoryName <span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span> directoryName <span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">os</span>.<span style="color: black;">makedirs</span><span style="color: black;">&#40;</span> directoryName <span style="color: black;">&#41;</span>
&nbsp;
folderName      = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
how_many_files  = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
junk_len        = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
createLocalDirectory<span style="color: black;">&#40;</span> folderName <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, how_many_files <span style="color: black;">&#41;</span>:  
  junk =  <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%%0%dX&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">random</span>.<span style="color: black;">getrandbits</span><span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span>
  path = folderName + <span style="color: #483d8b;">&quot;/&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;.txt&quot;</span>
  f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> path, <span style="color: #483d8b;">'w'</span> <span style="color: black;">&#41;</span>
  f.<span style="color: black;">write</span><span style="color: black;">&#40;</span> junk <span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">print</span> f
  f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;submitHeadline=Generate+Junk+Files&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;bm_description=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;T=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Generate+Junk+Files+@+http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;t=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/04/24/generate-junk-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search In One File from Keywords in Another File</title>
		<link>http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/</link>
		<comments>http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 04:49:00 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=939</guid>
		<description><![CDATA[I needed to see if this list of email addresses were found in a logs file. So I had one file with a list of email addresses. Another file is a list emails sent. I needed to make sure that the emails were sent. Here&#8217;s a quick Python script I put together that does this:

import [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to see if this list of email addresses were found in a logs file. So I had one file with a list of email addresses. Another file is a list emails sent. I needed to make sure that the emails were sent. Here&#8217;s a quick Python script I put together that does this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> searchInLogFile<span style="color: black;">&#40;</span> FILE, query <span style="color: black;">&#41;</span>:  
  FILE.<span style="color: black;">seek</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>  
  <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> LogFile:
    logLine = line.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">lstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> query, logLine, <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This file has a list (\r\n delimited) email addresses.</span>
EmailListFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;email-list-internal.txt&quot;</span>, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This is the log file which we'll use to see if email addresses are in here.</span>
LogFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;POST20100201.log&quot;</span>, <span style="color: #483d8b;">&quot;r&quot;</span> <span style="color: black;">&#41;</span>
&nbsp;
EmailFound = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
EmailNotFound = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
breakTime = <span style="color: #ff4500;">0</span>
<span style="color: #808080; font-style: italic;"># 0 = does the whole list</span>
EmailsToSearchFor = <span style="color: #ff4500;">0</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> emailLine <span style="color: #ff7700;font-weight:bold;">in</span> EmailListFile:
  <span style="color: #dc143c;">email</span> = emailLine.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">lstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> searchInLogFile<span style="color: black;">&#40;</span> LogFile, <span style="color: #dc143c;">email</span> <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">email</span>, <span style="color: #483d8b;">&quot;was found&quot;</span>
    EmailFound.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">email</span> <span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">email</span>, <span style="color: #483d8b;">&quot;not found&quot;</span>
    EmailNotFound.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">email</span> <span style="color: black;">&#41;</span>  
&nbsp;
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> EmailsToSearchFor <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>:
    breakTime += <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> breakTime == EmailsToSearchFor <span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">break</span><span style="color: #66cc66;">;</span>
&nbsp;
LogFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
EmailListFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Log results to a file.</span>
OutputFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;output.log&quot;</span>, <span style="color: #483d8b;">&quot;w&quot;</span> <span style="color: black;">&#41;</span>
&nbsp;
divider = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>======== Found ========================================&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> divider
OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> divider <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> EmailFound:
  <span style="color: #ff7700;font-weight:bold;">print</span> i
  OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + i <span style="color: black;">&#41;</span>
&nbsp;
divider = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>======== Not Found ====================================&quot;</span>  
<span style="color: #ff7700;font-weight:bold;">print</span> divider
OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> divider <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> EmailNotFound:
  <span style="color: #ff7700;font-weight:bold;">print</span> i
  OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + i <span style="color: black;">&#41;</span>
&nbsp;
OutputFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Pretty straightforward. The script also writes a file called &#8220;output.log&#8221; which has a list of emails that were found (marked under &#8220;found&#8221;) and not found (marked under &#8220;not found&#8221;). </p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;submitHeadline=Search+In+One+File+from+Keywords+in+Another+File&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;bm_description=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;T=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Search+In+One+File+from+Keywords+in+Another+File+@+http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;t=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Latest File</title>
		<link>http://www.shinylight.com/2010/02/04/get-latest-file/</link>
		<comments>http://www.shinylight.com/2010/02/04/get-latest-file/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 03:37:31 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Automation / Scripting]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=794</guid>
		<description><![CDATA[In my last post, I made a quick script that checks for the date. It was very limiting, since it used the dir command. This one uses several date/time Python modules and is more capable.

import os, os.path, stat, time
from datetime import date, timedelta, datetime
&#160;
# Reference
# http://docs.python.org/library/datetime.html
# http://docs.python.org/library/time.html
&#160;
def getFileDate&#40; filenamePath &#41;:    
&#160;
  [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.shinylight.com/2010/01/30/compress-and-move-log-files/">my last post</a>, I made a quick script that checks for the date. It was very limiting, since it used the dir command. This one uses several date/time Python modules and is more capable.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>, <span style="color: #dc143c;">stat</span>, <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">datetime</span> <span style="color: #ff7700;font-weight:bold;">import</span> date, timedelta, <span style="color: #dc143c;">datetime</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Reference</span>
<span style="color: #808080; font-style: italic;"># http://docs.python.org/library/datetime.html</span>
<span style="color: #808080; font-style: italic;"># http://docs.python.org/library/time.html</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> getFileDate<span style="color: black;">&#40;</span> filenamePath <span style="color: black;">&#41;</span>:    
&nbsp;
  used = <span style="color: #dc143c;">os</span>.<span style="color: #dc143c;">stat</span><span style="color: black;">&#40;</span> filenamePath <span style="color: black;">&#41;</span>.<span style="color: black;">st_mtime</span>      
  year, day, month, hour, minute, second = <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span>used<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span>
  objDateTime = <span style="color: #dc143c;">datetime</span><span style="color: black;">&#40;</span>year, day, month, hour, minute, second<span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">return</span> objDateTime
&nbsp;
  <span style="color: #808080; font-style: italic;"># Ways to reference this DateTime Object</span>
  <span style="color: #808080; font-style: italic;"># objDateTime.strftime(&quot;%Y-%m-%d %I:%M %p&quot;)</span>
  <span style="color: #808080; font-style: italic;"># objDateTime.year</span>
  <span style="color: #808080; font-style: italic;"># objDateTime.month</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> isDaysOldFromNow<span style="color: black;">&#40;</span> filenamepath, days <span style="color: black;">&#41;</span>:
&nbsp;
  <span style="color: #808080; font-style: italic;"># Checks how old a file is. Is it older than &quot;days&quot; [variable] days?</span>
  inTimeRange = <span style="color: #008000;">False</span>  
  timeDeltaDiff = <span style="color: black;">&#40;</span> <span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>-getFileDate<span style="color: black;">&#40;</span> filenamepath <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>.<span style="color: black;">days</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Check if the file's date is days old or less:</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> timeDeltaDiff <span style="color: #66cc66;">&gt;</span>= days <span style="color: black;">&#41;</span>:
    inTimeRange = <span style="color: #008000;">True</span>  
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">return</span> inTimeRange
&nbsp;
fname = <span style="color: #483d8b;">&quot;C:/temp/decision2.pdf&quot;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;"># Set this variable to check if the file is this days old</span>
howOld = <span style="color: #ff4500;">3</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> isDaysOldFromNow<span style="color: black;">&#40;</span> fname, howOld <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> fname, <span style="color: #483d8b;">&quot;is more than&quot;</span>, howOld, <span style="color: #483d8b;">&quot;days old&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> fname, <span style="color: #483d8b;">&quot;is NOT more than&quot;</span>, howOld, <span style="color: #483d8b;">&quot;days old&quot;</span></pre></div></div>

<p>Output:<br />
<img src="http://www.shinylight.com/wp-content/uploads/2010/02/walk1.gif" alt="" title="walk1" width="546" height="387" class="alignnone size-full wp-image-795" /></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;submitHeadline=Get+Latest+File&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;bm_description=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;T=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Get+Latest+File+@+http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;t=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/02/04/get-latest-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compress and Move Log Files</title>
		<link>http://www.shinylight.com/2010/01/30/compress-and-move-log-files/</link>
		<comments>http://www.shinylight.com/2010/01/30/compress-and-move-log-files/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 23:51:10 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Automation / Scripting]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=788</guid>
		<description><![CDATA[Sometimes log files bog a system down. For one of our servers, I made this little Python script that compresses (via WinRAR) the log files in a directory, and then moves them to a backup location. The only little catch is that I wanted to leave the latest log files for in that directory. Log [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes log files bog a system down. For one of our servers, I made this little Python script that compresses (via WinRAR) the log files in a directory, and then moves them to a backup location. The only little catch is that I wanted to leave the latest log files for in that directory. Log files are created daily, so the the latest log files have a datestamp of today. Here&#8217;s how I did it.</p>
<p>First Create the Python Script:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
&nbsp;
dateStamp  = <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%Y-%m-%d&quot;</span><span style="color: black;">&#41;</span> 
imsLogPath = <span style="color: #483d8b;">'d:<span style="color: #000099; font-weight: bold;">\\</span>LogFiles<span style="color: #000099; font-weight: bold;">\\</span>'</span>                     
<span style="color: #808080; font-style: italic;"># Don't use a mapped drive but use UNC for network drives. Task Schedule seems to choke when it calls Python.</span>
newRARPath = <span style="color: #483d8b;">'&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>192.168.1.2<span style="color: #000099; font-weight: bold;">\\</span>Root<span style="color: #000099; font-weight: bold;">\\</span>backups<span style="color: #000099; font-weight: bold;">\\</span>'</span> + dateStamp + <span style="color: #483d8b;">'.rar&quot;'</span>
rarPath    = <span style="color: #483d8b;">'&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>Program Files<span style="color: #000099; font-weight: bold;">\\</span>WinRAR<span style="color: #000099; font-weight: bold;">\\</span>rar.exe&quot; a -m5 '</span> + newRARPath 
&nbsp;
<span style="color: #808080; font-style: italic;"># Get Latest Files</span>
smtpLatest   = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;SMTP*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
postLatest   = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;POST*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
ischedLatest = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;iSched*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
relayLatest  = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;Relay*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
qengLatest   = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;Qeng*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Get List of All Files</span>
allFiles     = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Remove Latest Files from All Files List</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> smtpLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> postLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> ischedLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> relayLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> qengLatest <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># allFiles Array Has the list of files</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Flatten Array allFiles to be used as a parameter in system command</span>
flatLogPathList = <span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> filenameWithPath <span style="color: #ff7700;font-weight:bold;">in</span> allFiles:
  flatLogPathList = flatLogPathList + imsLogPath + filenameWithPath + <span style="color: #483d8b;">&quot; &quot;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># Execute WinRar</span>
path = rarPath + <span style="color: #483d8b;">&quot; &quot;</span> + flatLogPathList.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'&quot;'</span> + path + <span style="color: #483d8b;">'&quot;'</span> <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Delete all log files</span>
<span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'&quot;del '</span> + flatLogPathList.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'&quot;'</span> <span style="color: black;">&#41;</span></pre></div></div>

<p>Then I set up the Scheduled Task:</p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/01/ims-1.gif" alt="" title="ims-1" width="405" height="448" class="alignnone size-full wp-image-789" /></p>
<p>With these Settings:</p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/01/ims-2.gif" alt="" title="ims-2" width="403" height="448" class="alignnone size-full wp-image-790" /></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;submitHeadline=Compress+and+Move+Log+Files&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;bm_description=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;T=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Compress+and+Move+Log+Files+@+http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;t=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/01/30/compress-and-move-log-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursion vs For-Loop</title>
		<link>http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/</link>
		<comments>http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 03:39:04 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=703</guid>
		<description><![CDATA[So I&#8217;m currently in process of reading the infamous &#8220;Code Complete&#8221; by Steve McConnell. So far it&#8217;s been an amazing book and I definitely guarantee it to any programmer out there. I&#8217;ve just read the section on recursion and it mentioned how doing recursion for a factorial (or fibonacci) function is not as efficient as [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m currently in process of reading the infamous <a href="http://www.stevemcconnell.com/cc.htm">&#8220;Code Complete&#8221;</a> by Steve McConnell. So far it&#8217;s been an amazing book and I definitely guarantee it to any programmer out there. I&#8217;ve just read the section on recursion and it mentioned how doing recursion for a factorial (or fibonacci) function is not as efficient as a for-loop iteration. I guess I never thought about it, since in computer science I was always shoved recursion down my throat when doing factorials. I agree with him that computer science professors are eager to apply the idea of recursion on factorials, but I&#8217;ve never remembered a professor mention that it&#8217;s not the most efficient way. McConnell states in the book that doing recursion in factorials:</p>
<ol>
<li>Is not as fast as a for-loop.</li>
<li>Not as clear to read as a for-loop.</li>
<li>Use of run-time memory is unpredictable.</li>
</ol>
<p>Just for fun, I wanted to test his point on speed. This is a Python script that tests the average speed of a factorial using a for-loop or recursion. I noticed that for numbers less than 3000! the time it took for both functions were exactly the same. It was only when I bumped it up to <a href="http://www.comp.nus.edu.sg/~gem1501/factorial5000.txt">5000!, which is a huge number</a> (16,327 digits). Luckily Python lets you work with very large numbers easily. Just had to increase the number of recursion calls in Python from the default 1000.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> win32api
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">setrecursionlimit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">10000</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> factorial_forloop<span style="color: black;">&#40;</span> n <span style="color: black;">&#41;</span>:
  count = <span style="color: #ff4500;">1</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> n, <span style="color: #ff4500;">0</span>, -<span style="color: #ff4500;">1</span> <span style="color: black;">&#41;</span>:
    count = count <span style="color: #66cc66;">*</span> i  
  <span style="color: #ff7700;font-weight:bold;">return</span> count
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> factorial_recursion<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span> n == <span style="color: #ff4500;">0</span>:
     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span>
  <span style="color: #ff7700;font-weight:bold;">else</span>:
     <span style="color: #ff7700;font-weight:bold;">return</span> n <span style="color: #66cc66;">*</span> factorial_recursion<span style="color: black;">&#40;</span>n-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
&nbsp;
total_time_recursion = <span style="color: #ff4500;">0</span>
total_time_forloop   = <span style="color: #ff4500;">0</span>
number_of_tries      = <span style="color: #ff4500;">500</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">1</span>, number_of_tries <span style="color: black;">&#41;</span>:
&nbsp;
  start = win32api.<span style="color: black;">GetTickCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  factorial_recursion<span style="color: black;">&#40;</span> <span style="color: #ff4500;">5000</span> <span style="color: black;">&#41;</span>
  end = win32api.<span style="color: black;">GetTickCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  total = end - start  
  total_time_recursion += total
&nbsp;
&nbsp;
  start = win32api.<span style="color: black;">GetTickCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  factorial_forloop<span style="color: black;">&#40;</span> <span style="color: #ff4500;">5000</span> <span style="color: black;">&#41;</span>
  end = win32api.<span style="color: black;">GetTickCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
  total = end - start
  total_time_forloop += total  
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>  
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Average time for recursion: &quot;</span>, <span style="color: black;">&#40;</span> total_time_recursion / <span style="color: #ff4500;">10</span> <span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> .001
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Average time for for-loop: &quot;</span>, <span style="color: black;">&#40;</span> total_time_forloop / <span style="color: #ff4500;">10</span> <span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> .001</pre></div></div>

<p>So in 500 tries, the results were as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Average time for recursion:  1.284 seconds
Average time for for-loop:   1.083 seconds</pre></div></div>

<p>It doesn&#8217;t seem by much but the results are interesting. But then again, a factorial is a very simple algorithm. In future posts I&#8217;ll try to test more complicated algorithms and see how they battle out. Also, this is Python. The results for C, C++, or Java may differ.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;submitHeadline=Recursion+vs+For-Loop&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;title=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;title=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;title=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;bm_description=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;T=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;title=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;title=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Recursion+vs+For-Loop+@+http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/&amp;t=Recursion+vs+For-Loop" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/01/18/recursion-vs-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>yUML and ColdFusion</title>
		<link>http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/</link>
		<comments>http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 06:45:15 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=594</guid>
		<description><![CDATA[I just tried to write a quick script in Python that scans CFCs and generates a yUML URL to diagram. I pointed my script to my root CFC path and I got a 13K strlen URL. I pasted it in the address bar to see what happened and I got the following:

Request-URI Too Large
&#160;
The requested [...]]]></description>
			<content:encoded><![CDATA[<p>I just tried to write a quick script in Python that scans CFCs and generates a yUML URL to diagram. I pointed my script to my root CFC path and I got a 13K strlen URL. I pasted it in the address bar to see what happened and I got the following:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Request-URI Too Large
&nbsp;
The requested URL's length exceeds the capacity limit for this server.
Apache/2.2.3 (Debian) Phusion_Passenger/2.0.2 Server at Ess000235.gtcust.grouptelecom.net Port 80</pre></div></div>

<p>I wonder what the limitation is. I suppose I&#8217;ll have to do a CFC per diagram and then bind them together somehow. I&#8217;m choosing Python so this script can be part of my build script.</p>
<p>Here&#8217;s the code so far, which of course, could be optimized:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># UML Syntax</span>
<span style="color: #808080; font-style: italic;"># http://yuml.me/diagram/class/[User|Property1;Property2|Method1();Method2()]</span>
<span style="color: #808080; font-style: italic;"># http://yuml.me/diagram/class/</span>
<span style="color: #808080; font-style: italic;"># [</span>
<span style="color: #808080; font-style: italic;">#   User</span>
<span style="color: #808080; font-style: italic;">#   |</span>
<span style="color: #808080; font-style: italic;">#     Property1;</span>
<span style="color: #808080; font-style: italic;">#     Property2</span>
<span style="color: #808080; font-style: italic;">#   |</span>
<span style="color: #808080; font-style: italic;">#     Method1();</span>
<span style="color: #808080; font-style: italic;">#     Method2()</span>
<span style="color: #808080; font-style: italic;">#  ]</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># Master Path</span>
ROOT_PATH = <span style="color: #483d8b;">'C:<span style="color: #000099; font-weight: bold;">\\</span>temp<span style="color: #000099; font-weight: bold;">\\</span>cf-yuml'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> SearchForFile<span style="color: black;">&#40;</span> rootpath, searchfor, includepath = <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>:
&nbsp;
  <span style="color: #808080; font-style: italic;"># Search for a file recursively from a root directory.</span>
  <span style="color: #808080; font-style: italic;">#  rootpath  = root directory to start searching from.</span>
  <span style="color: #808080; font-style: italic;">#  searchfor = regexp to search for, e.g.:</span>
  <span style="color: #808080; font-style: italic;">#                 search for *.jpg : \.exe$                     </span>
  <span style="color: #808080; font-style: italic;">#  includepath = appends the full path to the file</span>
  <span style="color: #808080; font-style: italic;">#                this attribute is optional</span>
  <span style="color: #808080; font-style: italic;"># Returns a list of filenames that can be used to loop</span>
  <span style="color: #808080; font-style: italic;"># through.</span>
  <span style="color: #808080; font-style: italic;">#</span>
  <span style="color: #808080; font-style: italic;"># TODO: Use the glob module instead. Could be faster.  </span>
  names = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
  append = <span style="color: #483d8b;">&quot;&quot;</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> root, dirs, files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span> rootpath <span style="color: black;">&#41;</span>: 
    <span style="color: #ff7700;font-weight:bold;">for</span> name <span style="color: #ff7700;font-weight:bold;">in</span> files:
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> searchfor, name <span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> includepath == <span style="color: #ff4500;">0</span>:
          root = <span style="color: #483d8b;">&quot;&quot;</span>          
        <span style="color: #ff7700;font-weight:bold;">else</span>:          
          append = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span>
        names.<span style="color: black;">append</span><span style="color: black;">&#40;</span> root + append + name <span style="color: black;">&#41;</span>        
  <span style="color: #ff7700;font-weight:bold;">return</span> names  
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> getCFCInfo <span style="color: black;">&#40;</span> FILE, path <span style="color: black;">&#41;</span>:
  FILE.<span style="color: black;">seek</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>  
  CFCLines = FILE.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  CFCFunctions  = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
  CFCProperties = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
  CFC           = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> CFCLines:
    <span style="color: #808080; font-style: italic;"># Get names of methods  </span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;^&lt;cffunction&quot;</span>, i , <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>:    
      CFCFunctions.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> r<span style="color: #483d8b;">'name<span style="color: #000099; font-weight: bold;">\s</span>*=<span style="color: #000099; font-weight: bold;">\s</span>*&quot;([<span style="color: #000099; font-weight: bold;">\w</span>$-]+)&quot;'</span>, i, <span style="color: #dc143c;">re</span>.<span style="color: black;">DOTALL</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span><span style="color: black;">&#41;</span>.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Get names of properties</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;^&lt;cfproperty&quot;</span>, i , <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>:    
      CFCProperties.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> r<span style="color: #483d8b;">'name<span style="color: #000099; font-weight: bold;">\s</span>*=<span style="color: #000099; font-weight: bold;">\s</span>*&quot;([<span style="color: #000099; font-weight: bold;">\w</span>$-]+)&quot;'</span>, i, <span style="color: #dc143c;">re</span>.<span style="color: black;">DOTALL</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span><span style="color: black;">&#41;</span>.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>     
&nbsp;
  CFC = <span style="color: black;">&#123;</span> <span style="color: #483d8b;">&quot;properties&quot;</span>:CFCProperties, <span style="color: #483d8b;">&quot;methods&quot;</span>:CFCFunctions <span style="color: black;">&#125;</span>  
&nbsp;
  <span style="color: #808080; font-style: italic;"># Generate URL</span>
  strFunctions  = <span style="color: #483d8b;">&quot;&quot;</span>
  strProperties = <span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> CFCFunctions:
    strFunctions  += i + <span style="color: #483d8b;">&quot;();&quot;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> CFCProperties:
    strProperties += i + <span style="color: #483d8b;">&quot;;&quot;</span>  
&nbsp;
  CFCFileName = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>([<span style="color: #000099; font-weight: bold;">\w</span>-]+)<span style="color: #000099; font-weight: bold;">\.</span>cfc$&quot;</span>, path, <span style="color: #dc143c;">re</span>.<span style="color: black;">DOTALL</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span><span style="color: black;">&#41;</span>.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>  
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;[&quot;</span> + CFCFileName + <span style="color: #483d8b;">&quot;|&quot;</span> + <span style="color: black;">&#40;</span> strProperties.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;|&quot;</span> <span style="color: #ff7700;font-weight:bold;">if</span> strProperties.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #483d8b;">&quot;&quot;</span> <span style="color: black;">&#41;</span> + strFunctions.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;]&quot;</span>  
&nbsp;
URL = <span style="color: #483d8b;">&quot;&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> SearchForFile<span style="color: black;">&#40;</span> ROOT_PATH, <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>cfc$&quot;</span>, <span style="color: #ff4500;">1</span> <span style="color: black;">&#41;</span>:
  CFCFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> i, <span style="color: #483d8b;">&quot;r&quot;</span> <span style="color: black;">&#41;</span>
  URL += getCFCInfo<span style="color: black;">&#40;</span> CFCFile, i <span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;,&quot;</span>
  CFCFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
URL = URL<span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;http://yuml.me/diagram/class/&quot;</span> + URL</pre></div></div>

<p>I&#8217;ll keep working on this as time goes on. So far it just goes through all the CFC&#8217;s from the path you point to. It will crawl through all sub directories. There&#8217;s no relationship between classes, however. Not yet at least. </p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;submitHeadline=yUML+and+ColdFusion&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;title=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;title=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;title=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;bm_description=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;T=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;title=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;title=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+yUML+and+ColdFusion+@+http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/&amp;t=yUML+and+ColdFusion" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2009/12/29/yuml-and-coldfusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python and SQL Server</title>
		<link>http://www.shinylight.com/2009/12/27/python-and-sql-server/</link>
		<comments>http://www.shinylight.com/2009/12/27/python-and-sql-server/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 06:47:10 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=587</guid>
		<description><![CDATA[Setting up Python to connect to SQL Server was relatively easy. First, you select a DB API driver. I chose pyodbc because I saw a Python article on Simple-Talk. There are two simple steps:

Install Pywin32. Get the latest. It&#8217;s a dependency for pyodbc.
Install pyodbc. Get it for the version of Python you&#8217;re using.

Once you&#8217;ve done [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up Python to connect to SQL Server was relatively easy. First, you select a <a href="http://sourceforge.net/projects/pyodbc/">DB API driver</a>. I chose pyodbc because I saw a <a href="http://www.simple-talk.com/sql/database-administration/python-for-the-sql-server-dba/">Python article on Simple-Talk</a>. There are two simple steps:</p>
<ol>
<li><u><a href="http://sourceforge.net/projects/pywin32/files/"><strong>Install Pywin32</strong></a></u>. Get the latest. It&#8217;s a dependency for pyodbc.</li>
<li><u><a href="http://code.google.com/p/pyodbc/downloads/list"><strong>Install pyodbc</strong></a></u>. Get it for the version of Python you&#8217;re using.</li>
</ol>
<p>Once you&#8217;ve done this, you can query your SQL Server db as so:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> pyodbc
&nbsp;
connection = pyodbc.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'DRIVER={SQL Server};SERVER=192.168.0.5;DATABASE=MyAwesomeDB;UID=sa;PWD=password'</span><span style="color: black;">&#41;</span>
cursor = connection.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;select * from states&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> cursor:
  <span style="color: #ff7700;font-weight:bold;">print</span> row.<span style="color: black;">StateID</span>, row.<span style="color: black;">Abbreviation</span>, row.<span style="color: black;">Name</span></pre></div></div>

<p>For more snippets and a tutorial, <a href="http://code.google.com/p/pyodbc/w/list">check out the documentation</a>. </p>
<p>Now let&#8217;s try something more interesting. Let&#8217;s try doing some inserts and see how long it takes.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> win32api
<span style="color: #ff7700;font-weight:bold;">import</span> uuid
<span style="color: #ff7700;font-weight:bold;">import</span> pyodbc 
&nbsp;
connection = pyodbc.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'DRIVER={SQL Server};SERVER=192.168.0.5;DATABASE=MrSkittles;UID=sa;PWD=password'</span><span style="color: black;">&#41;</span>
cursor = connection.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
_start = win32api.<span style="color: black;">GetTickCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">10000</span> <span style="color: black;">&#41;</span>:  
  <span style="color: #808080; font-style: italic;"># Let's insert two pieces of data, both random UUIDs. </span>
  sql = <span style="color: #483d8b;">&quot;INSERT INTO Manager VALUES( '&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span> uuid.<span style="color: black;">uuid4</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;', '&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span> uuid.<span style="color: black;">uuid4</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;' )&quot;</span>  
  cursor.<span style="color: black;">execute</span><span style="color: black;">&#40;</span> sql <span style="color: black;">&#41;</span>
  connection.<span style="color: black;">commit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
_end = win32api.<span style="color: black;">GetTickCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
_total = _end - _start
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Process took&quot;</span>, _total <span style="color: #66cc66;">*</span> .001, <span style="color: #483d8b;">&quot;seconds&quot;</span></pre></div></div>

<p>After some tests, 10,000 records took roughly 20-30 seconds. 1,000,000 records took 30 to 40 minutes. A bit slow, but it&#8217;s not a server machine. My machine is a Core Duo, 1.8Ghz x 2, at ~4GB with PAE on WindowsXP, but I ran this on a VMware VM with 1GB and SQL Server 2005 w/Windows Server 2003. The table was a two column table both varchar(50). On a server machine, it should be a helluva lot faster. </p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;submitHeadline=Python+and+SQL+Server&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;title=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;title=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2009/12/27/python-and-sql-server/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;title=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;bm_description=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;T=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;title=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;title=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2009/12/27/python-and-sql-server/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2009/12/27/python-and-sql-server/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Python+and+SQL+Server+@+http://www.shinylight.com/2009/12/27/python-and-sql-server/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2009/12/27/python-and-sql-server/&amp;t=Python+and+SQL+Server" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2009/12/27/python-and-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IIS Logs Scripts</title>
		<link>http://www.shinylight.com/2009/12/12/iis-logs-scripts/</link>
		<comments>http://www.shinylight.com/2009/12/12/iis-logs-scripts/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 06:19:35 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[IIS]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=560</guid>
		<description><![CDATA[While working with some IIS logs, I decided to start practicing my Python. I put together some handy Python functions to work with IIS Log files. These will come in handy. On a 3GB, 2.5GHz, running WinXP machine, these functions take about 3 seconds to process a 180MB Text file. Python code could be optimized [...]]]></description>
			<content:encoded><![CDATA[<p>While working with some IIS logs, I decided to start practicing my Python. I put together some handy Python functions to work with IIS Log files. These will come in handy. On a 3GB, 2.5GHz, running WinXP machine, these functions take about 3 seconds to process a 180MB Text file. Python code could be optimized to be faster if you&#8217;re dealing with larger sized files.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># An IIS log file can have various log properties. Everytime you add new columns to log for</span>
<span style="color: #808080; font-style: italic;"># in IIS, it creates a new row full of columns.</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
MainLogDelimiter = <span style="color: #483d8b;">&quot;#Software: Microsoft Internet Information Services 6.0&quot;</span>
TestFile         = <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>Dan<span style="color: #000099; font-weight: bold;">\\</span>IIS-Log-Import<span style="color: #000099; font-weight: bold;">\\</span>Logs<span style="color: #000099; font-weight: bold;">\\</span>not-the-same.txt&quot;</span>
BigTestFile      = <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>Dan<span style="color: #000099; font-weight: bold;">\\</span>IIS-Log-Import<span style="color: #000099; font-weight: bold;">\\</span>Logs<span style="color: #000099; font-weight: bold;">\\</span>ex090914<span style="color: #000099; font-weight: bold;">\\</span>ex090914.log&quot;</span>
LogsDir          = <span style="color: #483d8b;">&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>Dan<span style="color: #000099; font-weight: bold;">\\</span>IIS-Log-Import<span style="color: #000099; font-weight: bold;">\\</span>Logs&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> SearchForFile<span style="color: black;">&#40;</span> rootpath, searchfor, includepath = <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>:
&nbsp;
  <span style="color: #808080; font-style: italic;"># Search for a file recursively from a root directory.</span>
  <span style="color: #808080; font-style: italic;">#  rootpath  = root directory to start searching from.</span>
  <span style="color: #808080; font-style: italic;">#  searchfor = regexp to search for, e.g.:</span>
  <span style="color: #808080; font-style: italic;">#                 search for *.jpg : \.exe$                     </span>
  <span style="color: #808080; font-style: italic;">#  includepath = appends the full path to the file</span>
  <span style="color: #808080; font-style: italic;">#                this attribute is optional</span>
  <span style="color: #808080; font-style: italic;"># Returns a list of filenames that can be used to loop</span>
  <span style="color: #808080; font-style: italic;"># through.</span>
  <span style="color: #808080; font-style: italic;">#</span>
  <span style="color: #808080; font-style: italic;"># TODO: Use the glob module instead. Could be faster.  </span>
  names = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
  append = <span style="color: #483d8b;">&quot;&quot;</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> root, dirs, files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span> rootpath <span style="color: black;">&#41;</span>: 
    <span style="color: #ff7700;font-weight:bold;">for</span> name <span style="color: #ff7700;font-weight:bold;">in</span> files:
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> searchfor, name <span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> includepath == <span style="color: #ff4500;">0</span>:
          root = <span style="color: #483d8b;">&quot;&quot;</span>          
        <span style="color: #ff7700;font-weight:bold;">else</span>:          
          append = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span>
        names.<span style="color: black;">append</span><span style="color: black;">&#40;</span> root + append + name <span style="color: black;">&#41;</span>        
  <span style="color: #ff7700;font-weight:bold;">return</span> names  
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> isSameLogProperties<span style="color: black;">&#40;</span> FILE <span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># Tests to see if a log file has the same number of columns throughout</span>
  <span style="color: #808080; font-style: italic;"># This is in case new column properties were added/subtracted in the course</span>
  <span style="color: #808080; font-style: italic;"># of the log file.</span>
  FILE.<span style="color: black;">seek</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>
  SubLogs = FILE.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span> MainLogDelimiter <span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># SubLogs[0] Stores the number of different log variations in the log file  </span>
  SubLogs<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span> SubLogs <span style="color: black;">&#41;</span> - <span style="color: #ff4500;">1</span>    
&nbsp;
  <span style="color: #808080; font-style: italic;"># Grab the column names from the log file, separated by space</span>
  columns = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;^#Fields:<span style="color: #000099; font-weight: bold;">\s</span>([<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span>()<span style="color: #000099; font-weight: bold;">\s</span>]+)$&quot;</span>, SubLogs<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>   
  LogSameProperties = <span style="color: #008000;">True</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">2</span>, SubLogs<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #ff4500;">1</span> <span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># If there are columns</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span> columns <span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>:    
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> columns <span style="color: #66cc66;">!</span>= <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;^#Fields:<span style="color: #000099; font-weight: bold;">\s</span>([<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span>()<span style="color: #000099; font-weight: bold;">\s</span>]+)$&quot;</span>, SubLogs<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>, <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:        
        LogSameProperties = <span style="color: #008000;">False</span>
        <span style="color: #ff7700;font-weight:bold;">break</span>  
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">return</span> LogSameProperties
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> getFirstColumn<span style="color: black;">&#40;</span> FILE <span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># This gets the columns from a log file. It returns only the first columns, and ignores another column</span>
  <span style="color: #808080; font-style: italic;"># row that may exist in case new columns were added/subtracted in IIS. </span>
  <span style="color: #808080; font-style: italic;"># input: FILE</span>
  <span style="color: #808080; font-style: italic;"># output: 1 single element List</span>
  FILE.<span style="color: black;">seek</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>
  names = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
  <span style="color: #808080; font-style: italic;"># Grab the column names from the log file, separated by space</span>
  names.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;^#Fields:<span style="color: #000099; font-weight: bold;">\s</span>([<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span>()<span style="color: #000099; font-weight: bold;">\s</span>]+)$&quot;</span>, FILE.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span> MainLogDelimiter <span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> names
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> getAllColumns<span style="color: black;">&#40;</span> FILE <span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># This gets all the columns from a log file. </span>
  <span style="color: #808080; font-style: italic;"># input: FILE</span>
  <span style="color: #808080; font-style: italic;"># output: List</span>
  FILE.<span style="color: black;">seek</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>  
  names = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
  SubLogs = FILE.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span> MainLogDelimiter <span style="color: black;">&#41;</span>    
  <span style="color: #808080; font-style: italic;"># SubLogs[0] Stores the number of different log variations in the log file  </span>
  SubLogs<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span> SubLogs <span style="color: black;">&#41;</span> - <span style="color: #ff4500;">1</span>        
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">1</span>, SubLogs<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #ff4500;">1</span> <span style="color: black;">&#41;</span>:        
    names.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;^#Fields:<span style="color: #000099; font-weight: bold;">\s</span>([<span style="color: #000099; font-weight: bold;">\w</span><span style="color: #000099; font-weight: bold;">\-</span>()<span style="color: #000099; font-weight: bold;">\s</span>]+)$&quot;</span>, SubLogs<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>, <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>.<span style="color: black;">group</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>  
  <span style="color: #ff7700;font-weight:bold;">return</span> names  
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># EXAMPLE:</span>
<span style="color: #808080; font-style: italic;"># Loop through all the IIS log files in the directory</span>
<span style="color: #808080; font-style: italic;"># for file in SearchForFile( LogsDir, &quot;\.txt$&quot;, 1 ):  </span>
LogFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> <span style="color: #008000;">file</span>, <span style="color: #483d8b;">&quot;r&quot;</span> <span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> isSameLogProperties<span style="color: black;">&#40;</span> LogFile <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">file</span>, <span style="color: #483d8b;">&quot;the same&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">file</span>, <span style="color: #483d8b;">&quot;not the same&quot;</span>
LogFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;submitHeadline=IIS+Logs+Scripts&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;title=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;title=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2009/12/12/iis-logs-scripts/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;title=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;bm_description=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;T=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;title=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;title=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2009/12/12/iis-logs-scripts/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2009/12/12/iis-logs-scripts/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+IIS+Logs+Scripts+@+http://www.shinylight.com/2009/12/12/iis-logs-scripts/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2009/12/12/iis-logs-scripts/&amp;t=IIS+Logs+Scripts" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2009/12/12/iis-logs-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;ve Switched to Python from Perl</title>
		<link>http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/</link>
		<comments>http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 04:44:33 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[perl programming python ruby]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=494</guid>
		<description><![CDATA[So I&#8217;ve finally dumped Perl for my systems scripts. Partly was for maintainability. Overall, when doing some benchmarks myself, it seems that Perl beats Python in simple text parsing and file manipulation, which is most of the time is what I use it for. Ugh. I do find it though, that in most teams, Perl [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve finally dumped Perl for my systems scripts. Partly was for maintainability. Overall, when doing some benchmarks myself, it seems that Perl beats Python in simple text parsing and file manipulation, which is most of the time is what I use it for. Ugh. I do find it though, that in most teams, Perl can be cryptic and unnecessarily harder for one to jump into. Python solves this. I think Python (after playing around with it for about a week) is a much more elegant language. Python will be a great addition to my toolkit for system automation. Much easier to apply OOP principles and write readable code. It&#8217;s a pleasure to write in this language and I look forward to learning more about it. </p>
<p>Also, while searching for performance tests on which language was &#8220;faster,&#8221; I ran across this site: <a href="http://dada.perl.it/shootout/">The Great Win32 Computer Language Shootout</a> . Of course, not to be used as a definitive guide, it does serve as a baseline, I think, for very simplistic tasks in a language. </p>
<p>On a related note, here&#8217;s a great video I saw on <a href="http://www.softdevtube.com/2009/12/07/python-in-the-enterprise-how-to-get-permission/">&#8220;Python in the Enterprise &#8211; How to Get Permission&#8221;</a>:</p>
<blockquote><p>If you start your own company or run your own project you can usually choose the programming language, but if you work for a large company there are probably architects and others who keep a tight rein on approved technology. How do you steer a big ship towards dynamic programming languages, and how fast can it turn? Come hear the story of one software developer employee who in 20 months facilitated the adoption of Python as the standard scripting language for an enterprise with 25,000 employees. Leave with ideas for advancing dynamic programming languages in your workplace, and with hope that change is possible.</p></blockquote>
<p>I looked into Ruby, and found various similarites. Python sold me due to its larger community and greater applications in the wild. I took a look at PHP for system scripting and it wasn&#8217;t fast enough for parsing large files. Lastly, I thought about <a href="http://www.shinylight.com/2009/09/26/javascript-for-the-windows-command-console/">JavaScript on the console via JSDB</a> but then realized its breadth of native library functions wasn&#8217;t as wide as that of Python. I really love that Python is getting a lot of momentum from Google and Microsoft is doing more to support the IronPython (Python on .NET) platform.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;submitHeadline=I%26%238217%3Bve+Switched+to+Python+from+Perl&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;title=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;title=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;title=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;bm_description=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;T=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;title=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;title=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+I%26%238217%3Bve+Switched+to+Python+from+Perl+@+http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/&amp;t=I%26%238217%3Bve+Switched+to+Python+from+Perl" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2009/12/07/ive-switched-to-python-from-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
