<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Goldblog - Programming</title>
    <link>http://www.goldb.org/goldblog/</link>
    <description>Corey Goldberg - Technology | Software | Performance</description>
    <language>en-us</language>
    <copyright>Corey Goldberg</copyright>
    <lastBuildDate>Wed, 16 Apr 2008 17:32:03 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>corey@goldb.org</managingEditor>
    <webMaster>corey@goldb.org</webMaster>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=7c9eb21b-b241-4085-a21a-ee60215a4206</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,7c9eb21b-b241-4085-a21a-ee60215a4206.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,7c9eb21b-b241-4085-a21a-ee60215a4206.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7c9eb21b-b241-4085-a21a-ee60215a4206</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When working with data sets, a common task I need to do is slurp a csv file into a
nested data structure that contains a sequence of lists correlating to the rows and
values in the csv file. 
</p>
        <p>
For example... 
</p>
        <p>
File contents (foo.csv): 
</p>
        <pre>
          <code class="geekcode">10,20,30,40<br />
19,29,39,55<br />
16,21,31,59</code>
        </pre>
        <p>
Result: 
</p>
        <pre>
          <code class="geekcode">[['10', '20', '30', '40'],<br />
['19', '29', '39', '55'],<br />
['16', '21', '31', '59']]</code>
        </pre>
        <p>
To accomplish this. you could parse it inside a big honkin' list comprehension and
build our structure in one step: 
</p>
        <pre>
          <code class="geekcode">csv_file = 'foo.csv'<br />
value_lists = [line.split(',') for line in 
<br />
[line.strip() for line in open(csv_file, 'r').readlines()]]</code>
        </pre>
        <p>
You could also use the csv module from Python's standard library: 
</p>
        <pre>
          <code class="geekcode">import csv<br />
csv_file = 'foo.csv'<br />
value_lists = list(csv.reader(open(csv_file, 'r')))</code>
        </pre>
        <p>
The csv module has some useful tools for reading/writing csv files.  <a href="http://docs.python.org/lib/module-csv.html">Check
it out</a>. 
</p>
      </body>
      <title>Python - Slurping CSV Files Into Nested Lists</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,7c9eb21b-b241-4085-a21a-ee60215a4206.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/04/16/PythonSlurpingCSVFilesIntoNestedLists.aspx</link>
      <pubDate>Wed, 16 Apr 2008 17:32:03 GMT</pubDate>
      <description>&lt;p&gt;
When working with data sets, a common task I need to do is slurp a csv file into a
nested data structure that contains a sequence of lists correlating to the rows and
values in the csv file. 
&lt;/p&gt;
&lt;p&gt;
For example... 
&lt;/p&gt;
&lt;p&gt;
File contents (foo.csv): 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;10,20,30,40&lt;br&gt;
19,29,39,55&lt;br&gt;
16,21,31,59&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Result: 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;[['10', '20', '30', '40'],&lt;br&gt;
['19', '29', '39', '55'],&lt;br&gt;
['16', '21', '31', '59']]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
To accomplish this. you could parse it inside a big honkin' list comprehension and
build our structure in one step: 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;csv_file = 'foo.csv'&lt;br&gt;
value_lists = [line.split(',') for line in 
&lt;br&gt;
[line.strip() for line in open(csv_file, 'r').readlines()]]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
You could also use the csv module from Python's standard library: 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;import csv&lt;br&gt;
csv_file = 'foo.csv'&lt;br&gt;
value_lists = list(csv.reader(open(csv_file, 'r')))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The csv module has some useful tools for reading/writing csv files.&amp;nbsp; &lt;a href="http://docs.python.org/lib/module-csv.html"&gt;Check
it out&lt;/a&gt;. 
&lt;/p&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,7c9eb21b-b241-4085-a21a-ee60215a4206.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=cb77c066-abd7-46cf-8338-97d0a4bd8e97</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,cb77c066-abd7-46cf-8338-97d0a4bd8e97.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,cb77c066-abd7-46cf-8338-97d0a4bd8e97.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=cb77c066-abd7-46cf-8338-97d0a4bd8e97</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://jessenoller.com/">Jesse Noller</a> just blogged "<a href="http://jessenoller.com/2008/04/16/finding-python-people-is-hard/">Finding
Python people is hard</a>": 
</p>
        <p>
Here is a good quote regarding the difficulty in finding skilled Test Engineers with
Python experience: 
</p>
        <blockquote>
          <em>"Either you teach QA people automation/test engineering, or you try
to find a programmer who wants to learn/do test engineering and teaching them python.
It's a hard sell either way. I technically view QA as one discipline, Development
as another, but Test Engineering as the Hybrid of the two - and you need a strong
background in both."</em>
        </blockquote>
        <p>
I have seen lots of QA Engineers and Testers with little to no development/programming
experience. This seems to be such a valuable skill; why not learn some? The bar is
set really low with today's dynamic languages. Getting into some quick scripting for
data manipulation and building test harnesses is not a huge task. If a QA engineer
can't learn some simple programming in a week, would you trust his efficiency and
technical skills? 
</p>
        <p>
I agree with Jesse on this one. We need to see more Test Engineers and Developers
In Test. Unfortunately, this hybrid roll often falls through cracks as many people
view quality/testing vs. developing as a binary choice. 
</p>
      </body>
      <title>Developer/Testers Are Hard To Find</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,cb77c066-abd7-46cf-8338-97d0a4bd8e97.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/04/16/DeveloperTestersAreHardToFind.aspx</link>
      <pubDate>Wed, 16 Apr 2008 17:22:19 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://jessenoller.com/"&gt;Jesse Noller&lt;/a&gt; just blogged "&lt;a href="http://jessenoller.com/2008/04/16/finding-python-people-is-hard/"&gt;Finding
Python people is hard&lt;/a&gt;": 
&lt;/p&gt;
&lt;p&gt;
Here is a good quote regarding the difficulty in finding skilled Test Engineers with
Python experience: 
&lt;/p&gt;
&lt;blockquote&gt; &lt;em&gt;"Either you teach QA people automation/test engineering, or you try
to find a programmer who wants to learn/do test engineering and teaching them python.
It's a hard sell either way. I technically view QA as one discipline, Development
as another, but Test Engineering as the Hybrid of the two - and you need a strong
background in both."&lt;/em&gt; &lt;/blockquote&gt; 
&lt;p&gt;
I have seen lots of QA Engineers and Testers with little to no development/programming
experience. This seems to be such a valuable skill; why not learn some? The bar is
set really low with today's dynamic languages. Getting into some quick scripting for
data manipulation and building test harnesses is not a huge task. If a QA engineer
can't learn some simple programming in a week, would you trust his efficiency and
technical skills? 
&lt;/p&gt;
&lt;p&gt;
I agree with Jesse on this one. We need to see more Test Engineers and Developers
In Test. Unfortunately, this hybrid roll often falls through cracks as many people
view quality/testing vs. developing as a binary choice. 
&lt;/p&gt;
</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,cb77c066-abd7-46cf-8338-97d0a4bd8e97.aspx</comments>
      <category>Programming;Python;Testing</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=adc740b2-f661-41d8-a397-56c637477584</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,adc740b2-f661-41d8-a397-56c637477584.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,adc740b2-f661-41d8-a397-56c637477584.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=adc740b2-f661-41d8-a397-56c637477584</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong> New Pylot 1.1 release is available<br />
Visit: <a href="http://www.pylot.org/download.html">www.pylot.org/download.html</a></strong>
        </p>
        <p>
It contains some minor code cleanup and a new test case recorder contributed by David
Solomon. The recorder works with Windows and IE only. 
</p>
        <p>
It is a script that launches your web browser and records HTTP requests as you navigate.
While it records, it prints Pylot's XML test cases. The test cases are printed to
STDOUT, so just redirect it to a file and you will have a valid testcases.xml file
to use as Pylot input. 
</p>
        <p>
The pylot_recorder script is included in the lib directory of Pylot 1.1. 
</p>
        <p>
View the recorder's source code from the SVN trunk:<br /><a href="http://code.google.com/p/pylt/source/browse/trunk/lib/pylot_recorder.py">http://code.google.com/p/pylt/source/browse/trunk/lib/pylot_recorder.py</a></p>
        <p>
(It can't handle some complex scenarios, but is useful for recording simple GET and
POST requests from web applications) 
</p>
      </body>
      <title>Pylot 1.1 - New Release With Test Case Recorder</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,adc740b2-f661-41d8-a397-56c637477584.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/04/14/Pylot11NewReleaseWithTestCaseRecorder.aspx</link>
      <pubDate>Mon, 14 Apr 2008 13:19:25 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt; New Pylot 1.1 release is available&lt;br&gt;
Visit: &lt;a href="http://www.pylot.org/download.html"&gt;www.pylot.org/download.html&lt;/a&gt; &lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
It contains some minor code cleanup and a new test case recorder contributed by David
Solomon. The recorder works with Windows and IE only. 
&lt;/p&gt;
&lt;p&gt;
It is a script that launches your web browser and records HTTP requests as you navigate.
While it records, it prints Pylot's XML test cases. The test cases are printed to
STDOUT, so just redirect it to a file and you will have a valid testcases.xml file
to use as Pylot input. 
&lt;/p&gt;
&lt;p&gt;
The pylot_recorder script is included in the lib directory of Pylot 1.1. 
&lt;/p&gt;
&lt;p&gt;
View the recorder's source code from the SVN trunk:&lt;br&gt;
&lt;a href="http://code.google.com/p/pylt/source/browse/trunk/lib/pylot_recorder.py"&gt;http://code.google.com/p/pylt/source/browse/trunk/lib/pylot_recorder.py&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
(It can't handle some complex scenarios, but is useful for recording simple GET and
POST requests from web applications) 
&lt;/p&gt;
</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,adc740b2-f661-41d8-a397-56c637477584.aspx</comments>
      <category>Programming;Pylot;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=e70bfd07-0dd2-459d-941f-b488420516b2</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,e70bfd07-0dd2-459d-941f-b488420516b2.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,e70bfd07-0dd2-459d-941f-b488420516b2.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=e70bfd07-0dd2-459d-941f-b488420516b2</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Python Cookbook has a recipe for splitting a list into roughly equal-sized pieces: 
</p>
        <p>
          <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425397"> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425397</a>
        </p>
        <p>
In the comments, there are several alterate implementations. Sebastian Hempel has
an interesting take on it using slicing for the calculation of the list lengths. It
basically looks like this: 
</p>
        <pre>
          <code class="geekcode">def split_seq(seq, num_pieces): start = 0 for i in xrange(num_pieces):
stop = start + len(seq[i::num_pieces]) yield seq[start:stop] start = stop </code>
        </pre>
        <p>
This version of the function distributes the remaindered items evenly over the first
few splits. 
</p>
        <p>
Example Usage: 
</p>
        <pre>
          <code class="geekcode">seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] for seq in split_seq(seq,
3): print seq </code>
        </pre>
      </body>
      <title>Split A List Into Roughly Equal Sized Pieces </title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,e70bfd07-0dd2-459d-941f-b488420516b2.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/04/10/SplitAListIntoRoughlyEqualSizedPieces.aspx</link>
      <pubDate>Thu, 10 Apr 2008 14:10:23 GMT</pubDate>
      <description>&lt;p&gt;
The Python Cookbook has a recipe for splitting a list into roughly equal-sized pieces: 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425397"&gt; http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425397&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In the comments, there are several alterate implementations. Sebastian Hempel has
an interesting take on it using slicing for the calculation of the list lengths. It
basically looks like this: 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;def split_seq(seq, num_pieces): start = 0 for i in xrange(num_pieces):
stop = start + len(seq[i::num_pieces]) yield seq[start:stop] start = stop &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
This version of the function distributes the remaindered items evenly over the first
few splits. 
&lt;/p&gt;
&lt;p&gt;
Example Usage: 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] for seq in split_seq(seq,
3): print seq &lt;/code&gt;&lt;/pre&gt;
</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,e70bfd07-0dd2-459d-941f-b488420516b2.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=a7fc9dce-412a-4510-9d3d-e271b2eb6ece</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,a7fc9dce-412a-4510-9d3d-e271b2eb6ece.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,a7fc9dce-412a-4510-9d3d-e271b2eb6ece.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=a7fc9dce-412a-4510-9d3d-e271b2eb6ece</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This script uses your system's ping utility to send an ICMP ECHO_REQUEST to a list
of hosts or devices. It uses a separate thread to ping each host/device. This can
be useful for measuring network latency and verifying hosts are alive. 
</p>
        <p>
Check out more info here: <a href="http://www.goldb.org/python_pinger.html">http://www.goldb.org/python_pinger.html</a></p>
        <hr />
        <pre>
          <code class="geekcode">#!/usr/bin/env python import re from subprocess import
Popen, PIPE from threading import Thread class Pinger(object): def __init__(self,
hosts): for host in hosts: pa = PingAgent(host) pa.start() class PingAgent(Thread):
def __init__(self, host): Thread.__init__(self) self.host = host def run(self): p
= Popen('ping -n 1 ' + self.host, stdout=PIPE) m = re.search('Average = (.*)ms', p.stdout.read())
if m: print 'Round Trip Time: %s ms -' % m.group(1), self.host else: print 'Error:
Invalid Response -', self.host if __name__ == '__main__': hosts = [ 'www.pylot.org',
'www.goldb.org', 'www.google.com', 'www.this_one_wont_work.com' ] Pinger(hosts) </code>
        </pre>
        <hr />
        <p>
Output:
</p>
        <pre>
          <code class="geekcode">Round Trip Time: 14 ms - www.yahoo.com Round Trip Time:
17 ms - www.goldb.org Round Trip Time: 30 ms - www.google.com Round Trip Time: 82
ms - www.pylot.org Error: Invalid Response - www.this_one_wont_work.com </code>
        </pre>
        <hr />
        <p>
          <em>Note: I only tested this on Windows. To run on other systems, it would only require
a one-line change.</em>
        </p>
      </body>
      <title>Python - Host/Device Ping Utility for Windows</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,a7fc9dce-412a-4510-9d3d-e271b2eb6ece.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/04/09/PythonHostDevicePingUtilityForWindows.aspx</link>
      <pubDate>Wed, 09 Apr 2008 15:40:04 GMT</pubDate>
      <description>&lt;p&gt;
This script uses your system's ping utility to send an ICMP ECHO_REQUEST to a list
of hosts or devices. It uses a separate thread to ping each host/device. This can
be useful for measuring network latency and verifying hosts are alive. 
&lt;/p&gt;
&lt;p&gt;
Check out more info here: &lt;a href="http://www.goldb.org/python_pinger.html"&gt;http://www.goldb.org/python_pinger.html&lt;/a&gt; 
&lt;/p&gt;
&lt;hr&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;#!/usr/bin/env python import re from subprocess import
Popen, PIPE from threading import Thread class Pinger(object): def __init__(self,
hosts): for host in hosts: pa = PingAgent(host) pa.start() class PingAgent(Thread):
def __init__(self, host): Thread.__init__(self) self.host = host def run(self): p
= Popen('ping -n 1 ' + self.host, stdout=PIPE) m = re.search('Average = (.*)ms', p.stdout.read())
if m: print 'Round Trip Time: %s ms -' % m.group(1), self.host else: print 'Error:
Invalid Response -', self.host if __name__ == '__main__': hosts = [ 'www.pylot.org',
'www.goldb.org', 'www.google.com', 'www.this_one_wont_work.com' ] Pinger(hosts) &lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;
Output:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;Round Trip Time: 14 ms - www.yahoo.com Round Trip Time:
17 ms - www.goldb.org Round Trip Time: 30 ms - www.google.com Round Trip Time: 82
ms - www.pylot.org Error: Invalid Response - www.this_one_wont_work.com &lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;
&lt;em&gt;Note: I only tested this on Windows. To run on other systems, it would only require
a one-line change.&lt;/em&gt; 
&lt;/p&gt;

</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,a7fc9dce-412a-4510-9d3d-e271b2eb6ece.aspx</comments>
      <category>Networking;Performance;Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=fd77f52f-9663-497d-850c-e040a128b1a6</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,fd77f52f-9663-497d-850c-e040a128b1a6.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,fd77f52f-9663-497d-850c-e040a128b1a6.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=fd77f52f-9663-497d-850c-e040a128b1a6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>"compared to Java code, XML is agile and flexible. Compared to Python code, XML
is a boat anchor, a ball and chain."<br />
    - Phillip J. Eby</em>
        </p>
        <p>
If you are new to Python and coming from Java (or C#, or other similar statically
typed OO language), these classic articles from <a href="http://dirtsimple.org/programming/index.html">PJE</a> and <a href="http://tomayko.com/">Ryan
Tomayko</a> are necessary reading: 
</p>
        <ul>
          <li>
            <a href="http://dirtsimple.org/2004/12/python-is-not-java.html">Python Is Not Java</a> (PJE)</li>
          <li>
            <a href="http://dirtsimple.org/2004/12/java-is-not-python-either.html">Java is not
Python, either</a> (PJE)</li>
          <li>
            <a href="http://dirtsimple.org/2004/12/python-interfaces-are-not-java.html">Python
Interfaces are not Java Interfaces</a> (PJE)</li>
          <li>
            <a href="http://tomayko.com/writings/the-static-method-thing">The Static Method Thing</a> (Tomayko)</li>
          <li>
            <a href="http://tomayko.com/writings/getters-setters-fuxors">Getters/Setters/Fuxors</a> (Tomayko)</li>
        </ul>
      </body>
      <title>Transitioning To Python From Java or C#</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,fd77f52f-9663-497d-850c-e040a128b1a6.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/03/20/TransitioningToPythonFromJavaOrC.aspx</link>
      <pubDate>Thu, 20 Mar 2008 16:13:57 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;"compared to Java code, XML is agile and flexible. Compared to Python code, XML
is a boat anchor, a ball and chain."&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; - Phillip J. Eby&lt;/em&gt; 
&lt;/p&gt;
&lt;p&gt;
If you are new to Python and coming from Java (or C#, or other similar statically
typed OO language), these classic articles from &lt;a href="http://dirtsimple.org/programming/index.html"&gt;PJE&lt;/a&gt; and &lt;a href="http://tomayko.com/"&gt;Ryan
Tomayko&lt;/a&gt; are necessary reading: 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://dirtsimple.org/2004/12/python-is-not-java.html"&gt;Python Is Not Java&lt;/a&gt; (PJE)&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://dirtsimple.org/2004/12/java-is-not-python-either.html"&gt;Java is not
Python, either&lt;/a&gt; (PJE)&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://dirtsimple.org/2004/12/python-interfaces-are-not-java.html"&gt;Python
Interfaces are not Java Interfaces&lt;/a&gt; (PJE)&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://tomayko.com/writings/the-static-method-thing"&gt;The Static Method Thing&lt;/a&gt; (Tomayko)&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://tomayko.com/writings/getters-setters-fuxors"&gt;Getters/Setters/Fuxors&lt;/a&gt; (Tomayko)&lt;/li&gt;
&lt;/ul&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,fd77f52f-9663-497d-850c-e040a128b1a6.aspx</comments>
      <category>Java;Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=40cfef5d-47a7-4b52-965c-3c01ac229108</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,40cfef5d-47a7-4b52-965c-3c01ac229108.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,40cfef5d-47a7-4b52-965c-3c01ac229108.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=40cfef5d-47a7-4b52-965c-3c01ac229108</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I love this <a href="http://lesscode.org/2006/03/12/someone-tell-gosling/">sarcastic
rant</a> by <a href="http://tomayko.com/">Ryan Tomayko</a> from March 2006. 
In the article, he rubutts some of <a href="http://java.sys-con.com/read/193146.htm">James
Gosling's comments</a> regarding Java vs. dynamic languages.  Ryan pokes some
fun at comments about dynamic languages and why they should be taken seriously; rather
than thrown into the "scripting language ghetto". 
</p>
        <p>
My favorite part: 
</p>
        <blockquote>
          <em>
            <p>
"Dealing with questions on dynamic languages: 
</p>
            <p>
First, call anything not statically compiled a “scripting language”. Attempt to insinuate
that all languages without an explicit compilation step are not to be taken seriously
and that they are all equivalently shitty. Best results are achieved when you provide
no further explanation of the pros and cons of static and dynamic compilation and/or
typing and instead allow the reader to simply assume that there are a wealth of benefits
and very few, if any, disadvantages to static compilation. While the benefits of dynamic
languages–first realized millions of years ago in LISP and Smalltalk–are well understood
in academia, IT managers and Sun certified developers are perfectly accepting of our
static = professional / dynamic = amateurish labeling scheme. 
</p>
            <p>
This technique is also known to result in dynamic language advocates going absolute
bat-shit crazy and making complete fools of themselves. There have been no fewer than
three head explosions recorded as a result of this technique. 
</p>
            <p>
Also, avoid the term “dynamic language” at all cost. It’s important that the reader
not be exposed to the concepts separating scripting languages like bash, MS-DOS batch,
and perl-in-the-eighties from general purpose dynamic languages like Ruby, Python,
Smalltalk, and Perl present day." 
</p>
          </em>
        </blockquote>
      </body>
      <title>Dynamic Languages Don't Live In The Scripting Language Ghetto</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,40cfef5d-47a7-4b52-965c-3c01ac229108.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/03/16/DynamicLanguagesDontLiveInTheScriptingLanguageGhetto.aspx</link>
      <pubDate>Sun, 16 Mar 2008 15:08:57 GMT</pubDate>
      <description>&lt;p&gt;
I love this &lt;a href="http://lesscode.org/2006/03/12/someone-tell-gosling/"&gt;sarcastic
rant&lt;/a&gt; by &lt;a href="http://tomayko.com/"&gt;Ryan Tomayko&lt;/a&gt; from March 2006.&amp;nbsp;
In the article, he rubutts some of &lt;a href="http://java.sys-con.com/read/193146.htm"&gt;James
Gosling's comments&lt;/a&gt; regarding Java vs. dynamic languages.&amp;nbsp; Ryan pokes some
fun at comments about dynamic languages and why they should be taken seriously; rather
than thrown into the "scripting language ghetto". 
&lt;/p&gt;
&lt;p&gt;
My favorite part: 
&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt; 
&lt;p&gt;
"Dealing with questions on dynamic languages: 
&lt;/p&gt;
&lt;p&gt;
First, call anything not statically compiled a “scripting language”. Attempt to insinuate
that all languages without an explicit compilation step are not to be taken seriously
and that they are all equivalently shitty. Best results are achieved when you provide
no further explanation of the pros and cons of static and dynamic compilation and/or
typing and instead allow the reader to simply assume that there are a wealth of benefits
and very few, if any, disadvantages to static compilation. While the benefits of dynamic
languages–first realized millions of years ago in LISP and Smalltalk–are well understood
in academia, IT managers and Sun certified developers are perfectly accepting of our
static = professional / dynamic = amateurish labeling scheme. 
&lt;/p&gt;
&lt;p&gt;
This technique is also known to result in dynamic language advocates going absolute
bat-shit crazy and making complete fools of themselves. There have been no fewer than
three head explosions recorded as a result of this technique. 
&lt;/p&gt;
&lt;p&gt;
Also, avoid the term “dynamic language” at all cost. It’s important that the reader
not be exposed to the concepts separating scripting languages like bash, MS-DOS batch,
and perl-in-the-eighties from general purpose dynamic languages like Ruby, Python,
Smalltalk, and Perl present day." 
&lt;/p&gt;
&lt;/em&gt;&lt;/blockquote&gt;




</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,40cfef5d-47a7-4b52-965c-3c01ac229108.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=5553d63d-7590-4fc3-b6d8-574c6e9b8d0d</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,5553d63d-7590-4fc3-b6d8-574c6e9b8d0d.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,5553d63d-7590-4fc3-b6d8-574c6e9b8d0d.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=5553d63d-7590-4fc3-b6d8-574c6e9b8d0d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This script will output bytes received and transmitted for a local Windows machine
since the last reboot:
</p>
        <pre>
          <code class="geekcode"> import re from subprocess import Popen, PIPE p = Popen('net
statistics workstation', stdout=PIPE) for line in p.stdout: m = re.search('Bytes received\W+(.*)',
line) if m: print 'Bytes received: %s' % (m.group(1)) m = re.search('Bytes transmitted\W+(.*)',
line) if m: print 'Bytes transmitted: %s' % (m.group(1)) </code>
        </pre>
      </body>
      <title>Python - Bytes Received and Transmitted for Windows</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,5553d63d-7590-4fc3-b6d8-574c6e9b8d0d.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/03/04/PythonBytesReceivedAndTransmittedForWindows.aspx</link>
      <pubDate>Tue, 04 Mar 2008 17:55:14 GMT</pubDate>
      <description>&lt;p&gt;
This script will output bytes received and transmitted for a local Windows machine
since the last reboot:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; import re from subprocess import Popen, PIPE p = Popen('net
statistics workstation', stdout=PIPE) for line in p.stdout: m = re.search('Bytes received\W+(.*)',
line) if m: print 'Bytes received: %s' % (m.group(1)) m = re.search('Bytes transmitted\W+(.*)',
line) if m: print 'Bytes transmitted: %s' % (m.group(1)) &lt;/code&gt;&lt;/pre&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,5553d63d-7590-4fc3-b6d8-574c6e9b8d0d.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=3c63d7b0-5388-44f5-97f7-547df8838280</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,3c63d7b0-5388-44f5-97f7-547df8838280.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,3c63d7b0-5388-44f5-97f7-547df8838280.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=3c63d7b0-5388-44f5-97f7-547df8838280</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This script will output the last reboot date/time for a local Windows machine:
</p>
        <pre>
          <code class="geekcode"> import re from subprocess import Popen, PIPE p = Popen('net
statistics workstation', stdout=PIPE) m = re.search('(\d+/\d+/\d{4}.*[A|P]M)', p.stdout.read())
if m: print 'Last Reboot: %s' % (m.group(1)) </code>
        </pre>
        <p>
Output:
</p>
        <pre>
          <code class="geekcode">&gt;&gt; Last Reboot: 3/1/2008 1:51:41 PM</code>
        </pre>
        <p>
          <br />
          <br />
          <br />
        </p>
        <hr />
        <p>
          <em>* updated the original script thanks to Ian's comment below</em>
        </p>
      </body>
      <title>Python - Get Last Windows Reboot Date/Time</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,3c63d7b0-5388-44f5-97f7-547df8838280.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/03/04/PythonGetLastWindowsRebootDateTime.aspx</link>
      <pubDate>Tue, 04 Mar 2008 17:37:34 GMT</pubDate>
      <description>&lt;p&gt;
This script will output the last reboot date/time for a local Windows machine:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; import re from subprocess import Popen, PIPE p = Popen('net
statistics workstation', stdout=PIPE) m = re.search('(\d+/\d+/\d{4}.*[A|P]M)', p.stdout.read())
if m: print 'Last Reboot: %s' % (m.group(1)) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Output:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;&amp;gt;&amp;gt; Last Reboot: 3/1/2008 1:51:41 PM&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;
&lt;em&gt;* updated the original script thanks to Ian's comment below&lt;/em&gt;
&lt;/p&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,3c63d7b0-5388-44f5-97f7-547df8838280.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=aac4572a-95a8-4891-95b6-175d276a1b63</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,aac4572a-95a8-4891-95b6-175d276a1b63.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,aac4572a-95a8-4891-95b6-175d276a1b63.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=aac4572a-95a8-4891-95b6-175d276a1b63</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here is how to zero-pad single digit days or months in a date string:
</p>
        <pre>
          <code class="geekcode"> date = '3/2/2008' padded_date = time.strftime('%m/%d/%Y',
time.strptime(date,'%m/%d/%Y')) print padded_date </code>
        </pre>
        <pre>
          <code class="geekcode">&gt;&gt; 03/02/2008<br /></code>
        </pre>
      </body>
      <title>Python - Padding Single Digits In Dates</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,aac4572a-95a8-4891-95b6-175d276a1b63.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/03/03/PythonPaddingSingleDigitsInDates.aspx</link>
      <pubDate>Mon, 03 Mar 2008 19:52:15 GMT</pubDate>
      <description>&lt;p&gt;
Here is how to zero-pad single digit days or months in a date string:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; date = '3/2/2008' padded_date = time.strftime('%m/%d/%Y',
time.strptime(date,'%m/%d/%Y')) print padded_date &lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;&amp;gt;&amp;gt; 03/02/2008&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,aac4572a-95a8-4891-95b6-175d276a1b63.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=c04c9486-604c-4b04-a463-453ae404f5c0</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,c04c9486-604c-4b04-a463-453ae404f5c0.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,c04c9486-604c-4b04-a463-453ae404f5c0.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c04c9486-604c-4b04-a463-453ae404f5c0</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A palindrome is a sequence that reads the same in either direction.
</p>
        <p>
Here is function I wrote to check if a phrase is a palindrome:
</p>
        <pre>
          <code class="geekcode"> import re def is_palindrome(txt): txt = re.sub('\W+',
'', txt).lower() return txt == txt[::-1] </code>
        </pre>
        <p>
          <br />
        </p>
        <pre>
          <code class="geekcode"> phrase = "Go hang a salami, I'm a lasagna hog" print
is_palindrome(phrase) &gt;&gt; True </code>
        </pre>
      </body>
      <title>Python - Palindrome Checker</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,c04c9486-604c-4b04-a463-453ae404f5c0.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/03/02/PythonPalindromeChecker.aspx</link>
      <pubDate>Sun, 02 Mar 2008 15:15:08 GMT</pubDate>
      <description>&lt;p&gt;
A palindrome is a sequence that reads the same in either direction.
&lt;/p&gt;
&lt;p&gt;
Here is function I wrote to check if a phrase is a palindrome:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; import re def is_palindrome(txt): txt = re.sub('\W+',
'', txt).lower() return txt == txt[::-1] &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; phrase = "Go hang a salami, I'm a lasagna hog" print
is_palindrome(phrase) &amp;gt;&amp;gt; True &lt;/code&gt;&lt;/pre&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,c04c9486-604c-4b04-a463-453ae404f5c0.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=e5038a5a-19f4-47a6-8f01-06b0095657e8</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,e5038a5a-19f4-47a6-8f01-06b0095657e8.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,e5038a5a-19f4-47a6-8f01-06b0095657e8.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=e5038a5a-19f4-47a6-8f01-06b0095657e8</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img src="http://www.goldb.org/goldblog/cmg_images/real_programmers_binary.jpg" />
      </body>
      <title>Real Programmers Code In Binary</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,e5038a5a-19f4-47a6-8f01-06b0095657e8.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/02/15/RealProgrammersCodeInBinary.aspx</link>
      <pubDate>Fri, 15 Feb 2008 17:40:47 GMT</pubDate>
      <description>&lt;img src="http://www.goldb.org/goldblog/cmg_images/real_programmers_binary.jpg"&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,e5038a5a-19f4-47a6-8f01-06b0095657e8.aspx</comments>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=72f089dd-ba0c-4673-8965-b8e2415c5289</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,72f089dd-ba0c-4673-8965-b8e2415c5289.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,72f089dd-ba0c-4673-8965-b8e2415c5289.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=72f089dd-ba0c-4673-8965-b8e2415c5289</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I write a lot of command line tools and scripts in Python. Sometimes I need to kick
them off remotely. A simple way to do this is to launch a tiny web server that listens
for a specific request to start the script. 
</p>
        <p>
I add a "WebRequestHandler" class to my script and call it from my main method. There
is a "do_something()" method in the class. You call your code from this method. 
</p>
        <p>
All you have to do is launch your script and it will sit there and wait for requests.
If the request is bad, it spits back a 404 error. If the request path matches what
we are looking for (in this case "/foo"), the code is launched.
</p>
        <p>
Now you have an easy way to call your script remotely. Just open a browser and type
in the URL: http://your_server/foo, or call it with a tool like 'wget' or 'curl'. 
</p>
        <pre>
          <code class="geekcode"> import BaseHTTPServer class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self): if self.path == '/foo': self.send_response(200) self.do_something()
else: self.send_error(404) def do_something(self): print 'hello world' server = BaseHTTPServer.HTTPServer(('',80),
WebRequestHandler) server.serve_forever() <code></code></code>
        </pre>
        <p>
          <i>(this was adapted from a code sample in "Python In A Nutshell" by Alex Martelli)</i>
        </p>
      </body>
      <title>Python - 15 Line HTTP Server - Web Interface For Your Tools</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,72f089dd-ba0c-4673-8965-b8e2415c5289.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/02/12/Python15LineHTTPServerWebInterfaceForYourTools.aspx</link>
      <pubDate>Tue, 12 Feb 2008 15:11:55 GMT</pubDate>
      <description>&lt;p&gt;
I write a lot of command line tools and scripts in Python. Sometimes I need to kick
them off remotely. A simple way to do this is to launch a tiny web server that listens
for a specific request to start the script. 
&lt;/p&gt;
&lt;p&gt;
I add a "WebRequestHandler" class to my script and call it from my main method. There
is a "do_something()" method in the class. You call your code from this method. 
&lt;/p&gt;
&lt;p&gt;
All you have to do is launch your script and it will sit there and wait for requests.
If the request is bad, it spits back a 404 error. If the request path matches what
we are looking for (in this case "/foo"), the code is launched.
&lt;/p&gt;
&lt;p&gt;
Now you have an easy way to call your script remotely. Just open a browser and type
in the URL: http://your_server/foo, or call it with a tool like 'wget' or 'curl'. 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; import BaseHTTPServer class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self): if self.path == '/foo': self.send_response(200) self.do_something()
else: self.send_error(404) def do_something(self): print 'hello world' server = BaseHTTPServer.HTTPServer(('',80),
WebRequestHandler) server.serve_forever() &lt;code&gt;&lt;/code&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;i&gt;(this was adapted from a code sample in "Python In A Nutshell" by Alex Martelli)&lt;/i&gt; 
&lt;/p&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,72f089dd-ba0c-4673-8965-b8e2415c5289.aspx</comments>
      <category>Programming;Python;Web</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=44f59b04-2a4a-4bbb-8cba-8a0986e677b0</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,44f59b04-2a4a-4bbb-8cba-8a0986e677b0.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,44f59b04-2a4a-4bbb-8cba-8a0986e677b0.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=44f59b04-2a4a-4bbb-8cba-8a0986e677b0</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In many programming languages you can't terminate a thread directly.  Python
is no different.  Rather than termintaing a thread from the code that spawned
it, you just a pass a flag to the thread that tells it to terminate itself. 
Typically a thread will run in a loop, periodically checking this flag so it knows
if it should continue or not.  To terminate the thread from the outside, you
just set its flag to die. 
</p>
        <p>
I was using this idiom in Python by setting a boolean flag in my spawned thread. 
</p>
        <p>
So a simplified thread class would look something like this: 
</p>
        <pre>
          <code class="geekcode"> class MyThread(threading.Thread): def __init__(self,
num): threading.Thread.__init__(self) self.running = True self.num = num def stop(self):
self.running = False def run(self): while self.running: print 'hello from thread %d'
% self.num time.sleep(1) </code>
        </pre>
        <p>
I just read an old post in comp.lang.python that pointed to a recipe in the Python
Cookbook that suggests using threading.Event() rather than a simple boolean flag. 
</p>
        <p>
So the thread class would look something like this: 
</p>
        <pre>
          <code class="geekcode"> class MyThread(threading.Thread): def __init__(self,
num): threading.Thread.__init__(self) self.stop_event = threading.Event() self.num
= num def stop(self): self.stop_event.set() def run(self): while not self.stop_event.isSet():
print 'hello from thread %d' % self.num time.sleep(1) </code>
        </pre>
        <p>
They work exactly the same. 
</p>
        <p>
I am just wondering what other flexibility threading.Event() gives you, and if there
is anything bad about using simple boolean checks to kill threads. I guess I will
have to look it up and play around a bit. 
</p>
      </body>
      <title>Python - Terminating Threads - Boolean Flag and threading.Event()</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,44f59b04-2a4a-4bbb-8cba-8a0986e677b0.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/02/11/PythonTerminatingThreadsBooleanFlagAndThreadingEvent.aspx</link>
      <pubDate>Mon, 11 Feb 2008 21:37:45 GMT</pubDate>
      <description>&lt;p&gt;
In many programming languages you can't terminate a thread directly.&amp;nbsp; Python
is no different.&amp;nbsp; Rather than termintaing a thread from the code that spawned
it, you just a pass a flag to the thread that tells it to terminate itself.&amp;nbsp;
Typically a thread will run in a loop, periodically checking this flag so it knows
if it should continue or not.&amp;nbsp; To terminate the thread from the outside, you
just set its flag to die. 
&lt;/p&gt;
&lt;p&gt;
I was using this idiom in Python by setting a boolean flag in my spawned thread. 
&lt;/p&gt;
&lt;p&gt;
So a simplified thread class would look something like this: 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; class MyThread(threading.Thread): def __init__(self,
num): threading.Thread.__init__(self) self.running = True self.num = num def stop(self):
self.running = False def run(self): while self.running: print 'hello from thread %d'
% self.num time.sleep(1) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
I just read an old post in comp.lang.python that pointed to a recipe in the Python
Cookbook that suggests using threading.Event() rather than a simple boolean flag. 
&lt;/p&gt;
&lt;p&gt;
So the thread class would look something like this: 
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; class MyThread(threading.Thread): def __init__(self,
num): threading.Thread.__init__(self) self.stop_event = threading.Event() self.num
= num def stop(self): self.stop_event.set() def run(self): while not self.stop_event.isSet():
print 'hello from thread %d' % self.num time.sleep(1) &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
They work exactly the same. 
&lt;/p&gt;
&lt;p&gt;
I am just wondering what other flexibility threading.Event() gives you, and if there
is anything bad about using simple boolean checks to kill threads. I guess I will
have to look it up and play around a bit. 
&lt;/p&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,44f59b04-2a4a-4bbb-8cba-8a0986e677b0.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=a4cea6a4-e7af-4b87-947e-deac35a1d14e</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,a4cea6a4-e7af-4b87-947e-deac35a1d14e.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,a4cea6a4-e7af-4b87-947e-deac35a1d14e.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=a4cea6a4-e7af-4b87-947e-deac35a1d14e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just installed the latest Alpha of Python 3000.
</p>
        <img src="http://www.goldb.org/goldblog/cmg_images/py3k_prompt.jpg" />
        <p>
So far so good...
</p>
      </body>
      <title>Rockin' Python 3000 Alpha (3.0a2)</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,a4cea6a4-e7af-4b87-947e-deac35a1d14e.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/02/10/RockinPython3000Alpha30a2.aspx</link>
      <pubDate>Sun, 10 Feb 2008 16:19:13 GMT</pubDate>
      <description>&lt;p&gt;
I just installed the latest Alpha of Python 3000.
&lt;/p&gt;
&lt;img src="http://www.goldb.org/goldblog/cmg_images/py3k_prompt.jpg"&gt; 
&lt;p&gt;
So far so good...
&lt;/p&gt;
</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,a4cea6a4-e7af-4b87-947e-deac35a1d14e.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=d580a435-97fb-420f-9c1b-3649cf60fde1</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,d580a435-97fb-420f-9c1b-3649cf60fde1.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,d580a435-97fb-420f-9c1b-3649cf60fde1.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=d580a435-97fb-420f-9c1b-3649cf60fde1</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sending HTTP Requests from a C# program seems unnecessarily hard.  I wrote a
small helper class to deal with sending and timing GET requests:<br /><a href="http://www.goldb.org/httpgetcsharp.html">http://www.goldb.org/httpgetcsharp.html</a></p>
        <p>
You use it like this:
</p>
        <pre>
          <code class="geekcode"> public class Program { static void Main(string[] args)
{ HTTPGet req = new HTTPGet(); req.Request("http://www.google.com"); Console.WriteLine(req.StatusLine);
Console.WriteLine(req.ResponseTime); } } </code>
        </pre>
      </body>
      <title>C# .NET 2.0 HTTP GET Class</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,d580a435-97fb-420f-9c1b-3649cf60fde1.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/02/06/CNET20HTTPGETClass.aspx</link>
      <pubDate>Wed, 06 Feb 2008 20:59:13 GMT</pubDate>
      <description>&lt;p&gt;
Sending HTTP Requests from a C# program seems unnecessarily hard.&amp;nbsp; I wrote a
small helper class to deal with sending and timing GET requests:&lt;br&gt;
&lt;a href="http://www.goldb.org/httpgetcsharp.html"&gt;http://www.goldb.org/httpgetcsharp.html&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
You use it like this:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt; public class Program { static void Main(string[] args)
{ HTTPGet req = new HTTPGet(); req.Request("http://www.google.com"); Console.WriteLine(req.StatusLine);
Console.WriteLine(req.ResponseTime); } } &lt;/code&gt;&lt;/pre&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,d580a435-97fb-420f-9c1b-3649cf60fde1.aspx</comments>
      <category>C#;Programming;Web</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=6ccfef1b-c4f4-4567-8261-7be3280716b8</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,6ccfef1b-c4f4-4567-8261-7be3280716b8.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,6ccfef1b-c4f4-4567-8261-7be3280716b8.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=6ccfef1b-c4f4-4567-8261-7be3280716b8</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Convert a number of seconds into a human readable time string HH:MM:SS 
</p>
        <p>
7046 seconds is: 1 hour 57 mins 26 secs, or 01:57:26 
</p>
        <p>
The Function:
</p>
        <pre>
          <code class="geekcode">def humanize_time(secs):<br />
mins, secs = divmod(secs, 60)<br />
hours, mins = divmod(mins, 60)<br />
return '%02d:%02d:%02d' % (hours, mins, secs)<br /></code>
        </pre>
        <p>
The Output:
</p>
        <pre>
          <code class="geekcode">print humanize_time(7046)<br />
&gt;&gt; 01:57:26<br /></code>
        </pre>
      </body>
      <title>Python - Convert Secs Into Human Readable Time String (HH:MM:SS)</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,6ccfef1b-c4f4-4567-8261-7be3280716b8.aspx</guid>
      <link>http://www.goldb.org/goldblog/2008/02/06/PythonConvertSecsIntoHumanReadableTimeStringHHMMSS.aspx</link>
      <pubDate>Wed, 06 Feb 2008 02:27:53 GMT</pubDate>
      <description>&lt;p&gt;
Convert a number of seconds into a human readable time string HH:MM:SS 
&lt;/p&gt;
&lt;p&gt;
7046 seconds is: 1 hour 57 mins 26 secs, or 01:57:26 
&lt;/p&gt;
&lt;p&gt;
The Function:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;def humanize_time(secs):&lt;br&gt;
mins, secs = divmod(secs, 60)&lt;br&gt;
hours, mins = divmod(mins, 60)&lt;br&gt;
return '%02d:%02d:%02d' % (hours, mins, secs)&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The Output:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;print humanize_time(7046)&lt;br&gt;
&amp;gt;&amp;gt; 01:57:26&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,6ccfef1b-c4f4-4567-8261-7be3280716b8.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=5e1bee53-241f-41cb-8671-83aa22ed46fa</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,5e1bee53-241f-41cb-8671-83aa22ed46fa.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,5e1bee53-241f-41cb-8671-83aa22ed46fa.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=5e1bee53-241f-41cb-8671-83aa22ed46fa</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The new issue of the Python Papers is out.  It includes a small article I wrote
called: Screen Scraping Web Pages 
</p>
        <p>
The issue can be downloaded here:  <a href="http://archive.pythonpapers.org/ThePythonPapersVolume2Issue4.pdf">The
Python Papers, Volume 2, Issue 4 (pdf)</a></p>
        <blockquote>
          <em> This tutorial shows how to programmatically retrieve a stock quote
from Google Finance.  It uses Python's high level Web API and screen scraping
with regular expressions. </em>
        </blockquote>
      </body>
      <title>The Python Papers - Screen Scraping Article</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,5e1bee53-241f-41cb-8671-83aa22ed46fa.aspx</guid>
      <link>http://www.goldb.org/goldblog/2007/12/18/ThePythonPapersScreenScrapingArticle.aspx</link>
      <pubDate>Tue, 18 Dec 2007 16:19:55 GMT</pubDate>
      <description>&lt;p&gt;
The new issue of the Python Papers is out.&amp;nbsp; It includes a small article I wrote
called: Screen Scraping Web Pages 
&lt;/p&gt;
&lt;p&gt;
The issue can be downloaded here:&amp;nbsp; &lt;a href="http://archive.pythonpapers.org/ThePythonPapersVolume2Issue4.pdf"&gt;The
Python Papers, Volume 2, Issue 4 (pdf)&lt;/a&gt; 
&lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt; This tutorial shows how to programmatically retrieve a stock quote
from Google Finance.&amp;nbsp; It uses Python's high level Web API and screen scraping
with regular expressions. &lt;/em&gt;&lt;/blockquote&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,5e1bee53-241f-41cb-8671-83aa22ed46fa.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=0e6f7811-d3ea-4bbe-b9f9-7e3eade4db13</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,0e6f7811-d3ea-4bbe-b9f9-7e3eade4db13.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,0e6f7811-d3ea-4bbe-b9f9-7e3eade4db13.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=0e6f7811-d3ea-4bbe-b9f9-7e3eade4db13</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was recently interviewed for the article:<br /><a href="http://www.odinjobs.com/blogs/careers/entry/python_experts_why_they_do">Python
Experts - Why They Do Python</a></p>
        <p>
I don't think I am even close to an "expert", but it was nice being asked to participate. 
</p>
      </body>
      <title>Python Experts - Why They Do Python</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,0e6f7811-d3ea-4bbe-b9f9-7e3eade4db13.aspx</guid>
      <link>http://www.goldb.org/goldblog/2007/12/17/PythonExpertsWhyTheyDoPython.aspx</link>
      <pubDate>Mon, 17 Dec 2007 20:13:41 GMT</pubDate>
      <description>&lt;p&gt;
I was recently interviewed for the article:&lt;br&gt;
&lt;a href="http://www.odinjobs.com/blogs/careers/entry/python_experts_why_they_do"&gt;Python
Experts - Why They Do Python&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
I don't think I am even close to an "expert", but it was nice being asked to participate. 
&lt;/p&gt;</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,0e6f7811-d3ea-4bbe-b9f9-7e3eade4db13.aspx</comments>
      <category>Programming;Python</category>
    </item>
    <item>
      <trackback:ping>http://www.goldb.org/goldblog/Trackback.aspx?guid=d0bf29b7-2313-4d49-aed6-6a0406589f99</trackback:ping>
      <pingback:server>http://www.goldb.org/goldblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.goldb.org/goldblog/PermaLink,guid,d0bf29b7-2313-4d49-aed6-6a0406589f99.aspx</pingback:target>
      <dc:creator>Corey Goldberg</dc:creator>
      <wfw:comment>http://www.goldb.org/goldblog/CommentView,guid,d0bf29b7-2313-4d49-aed6-6a0406589f99.aspx</wfw:comment>
      <wfw:commentRss>http://www.goldb.org/goldblog/SyndicationService.asmx/GetEntryCommentsRss?guid=d0bf29b7-2313-4d49-aed6-6a0406589f99</wfw:commentRss>
      <slash:comments>6</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here is a way to unzip files in Python.  If you have a zip containing multiple
files, you can unzip it like this:
</p>
        <pre>
          <code class="geekcode">import zipfile<br /><br />
fh = open('foo.zip', 'rb')<br />
z = zipfile.ZipFile(fh)<br />
for name in z.namelist():<br />
outfile = open(name, 'wb')<br />
outfile.write(z.read(name))<br />
outfile.close()<br />
fh.close()<br /></code>
        </pre>
      </body>
      <title>Python - Extracting Files From Zip Archives</title>
      <guid isPermaLink="false">http://www.goldb.org/goldblog/PermaLink,guid,d0bf29b7-2313-4d49-aed6-6a0406589f99.aspx</guid>
      <link>http://www.goldb.org/goldblog/2007/11/27/PythonExtractingFilesFromZipArchives.aspx</link>
      <pubDate>Tue, 27 Nov 2007 19:21:10 GMT</pubDate>
      <description>&lt;p&gt;
Here is a way to unzip files in Python.&amp;nbsp; If you have a zip containing multiple
files, you can unzip it like this:
&lt;/p&gt;
&lt;pre&gt;&lt;code class="geekcode"&gt;import zipfile&lt;br&gt;
&lt;br&gt;
fh = open('foo.zip', 'rb')&lt;br&gt;
z = zipfile.ZipFile(fh)&lt;br&gt;
for name in z.namelist():&lt;br&gt;
outfile = open(name, 'wb')&lt;br&gt;
outfile.write(z.read(name))&lt;br&gt;
outfile.close()&lt;br&gt;
fh.close()&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;
</description>
      <comments>http://www.goldb.org/goldblog/CommentView,guid,d0bf29b7-2313-4d49-aed6-6a0406589f99.aspx</comments>
      <category>Programming;Python</category>
    </item>
  </channel>
</rss>