<?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>The Number 42 &#187; Python</title>
	<atom:link href="http://www.thenumber42.net/category/computer-stuff/programming/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thenumber42.net</link>
	<description>Mostly about software testing, but a little bit about life, the universe, and everything</description>
	<lastBuildDate>Wed, 31 Mar 2010 01:52:14 +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>Cool Python Tricks</title>
		<link>http://www.thenumber42.net/2009/12/03/cool-python-tricks/</link>
		<comments>http://www.thenumber42.net/2009/12/03/cool-python-tricks/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 14:21:30 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/?p=203</guid>
		<description><![CDATA[This is a very good article with lots of cools things that Python can do.  Python Tips, Tricks, and Hacks
Link Summary

http://www.siafoo.net/article/52
]]></description>
			<content:encoded><![CDATA[<p>This is a very good article with lots of cools things that Python can do.  <a href="http://www.siafoo.net/article/52">Python Tips, Tricks, and Hacks</a></p>
<div class="link-summarizer">Link Summary
<ul>
<li><a href='http://www.siafoo.net/article/52'>http://www.siafoo.net/article/52</a></li>
</ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2009/12/03/cool-python-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending Email with Python</title>
		<link>http://www.thenumber42.net/2009/07/28/sending-email-with-python/</link>
		<comments>http://www.thenumber42.net/2009/07/28/sending-email-with-python/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 15:04:25 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Computer Stuff]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/?p=180</guid>
		<description><![CDATA[I feel like a proud father.  Yesterday I posted my first public Python recipe.  Go check it out: http://code.activestate.com/recipes/576858/.
Link Summary

http://code.activestate.com/recipes/576858/
]]></description>
			<content:encoded><![CDATA[<p>I feel like a proud father.  Yesterday I posted my first public Python recipe.  Go check it out: <a href="http://code.activestate.com/recipes/576858/">http://code.activestate.com/recipes/576858/</a>.</p>
<div class="link-summarizer">Link Summary
<ul>
<li><a href='http://code.activestate.com/recipes/576858/'>http://code.activestate.com/recipes/576858/</a></li>
</ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2009/07/28/sending-email-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Long Sleeps In Python</title>
		<link>http://www.thenumber42.net/2009/07/15/long-sleeps-in-python/</link>
		<comments>http://www.thenumber42.net/2009/07/15/long-sleeps-in-python/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 19:45:03 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[sleep]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/?p=169</guid>
		<description><![CDATA[There is a portion of my test infrastructure that requires long sleep periods for stability soak testing purposes.  So far the longest stability test run was 9 days.  Originally, I simply used the time.sleep() method from the Python library.  However, and I attribute this to VMware, I found that extremely inaccurate for [...]]]></description>
			<content:encoded><![CDATA[<p>There is a portion of my test infrastructure that requires long sleep periods for stability soak testing purposes.  So far the longest stability test run was 9 days.  Originally, I simply used the time.sleep() method from the Python library.  However, and I attribute this to VMware, I found that extremely inaccurate for long sleep durations.  My test controller is running in a VM and although I have nothing to confirm this I suspect that VMware is doing funny stuff under the covers with the OS timer and that is throwing off the accuracy of time.sleep().  Anyway, here is my solution to the problem.</p>
<pre class="python"><span style="color: #ff7700;font-weight:bold;">import</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> <span style="color: #dc143c;">datetime</span>, timedelta
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> longsleep<span style="color: black;">&#40;</span>minutes<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;
    The normal time.sleep() method is not very accurate from inside
    VMware when sleeping for long periods of time.  This method is
    accurate to within +/- 5 seconds of the desired sleep time period.
    For long periods on the order of hours or days this small inaccuracy
    is acceptable.
    &quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    sleepTimeSec = <span style="color: #ff4500;">60</span> * minutes
    now = <span style="color: #dc143c;">datetime</span>.<span style="color: black;">utcnow</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    td = timedelta<span style="color: black;">&#40;</span>seconds=sleepTimeSec<span style="color: black;">&#41;</span>
    endTime = now + td
    <span style="color: #ff7700;font-weight:bold;">while</span> now &lt;= endTime:
        <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
        now = <span style="color: #dc143c;">datetime</span>.<span style="color: black;">utcnow</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>The method is accurate to around +/- 5 seconds, but for really long sleep durations 5 seconds is no big deal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2009/07/15/long-sleeps-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Packet Creation With Python</title>
		<link>http://www.thenumber42.net/2009/05/26/packet-creation-with-python/</link>
		<comments>http://www.thenumber42.net/2009/05/26/packet-creation-with-python/#comments</comments>
		<pubDate>Tue, 26 May 2009 20:50:01 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/?p=151</guid>
		<description><![CDATA[I work at a company that designs and builds network routers, so you can imagine that on occasion I need to create custom Ethernet packets for testing.  For hardcore traffic testing we've got some really expensive packet generator hardware that can send packets at full line rate.  For my tests I don't need raw data [...]]]></description>
			<content:encoded><![CDATA[<p>I work at a company that designs and builds network routers, so you can imagine that on occasion I need to create custom Ethernet packets for testing.  For hardcore traffic testing we've got some really expensive packet generator hardware that can send packets at full line rate.  For my tests I don't need raw data throughput, but I do need the ability to customize packets.</p>
<p>Just today I found a really great package for Python called <a href="https://www.secdev.org/projects/scapy/">Scapy</a>.  With Scapy I can create arbitrary packets with arbitrary values and fire away.  It also supports packet capturing and has all kinds of features.  As I get more comfortable with Scapy I'll post some examples.  In the mean time, those of you who need to inject custom packets for testing into equipment go check it out.</p>
<div class="link-summarizer">Link Summary
<ul>
<li><a href='https://www.secdev.org/projects/scapy/'>https://www.secdev.org/projects/scapy/</a></li>
</ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2009/05/26/packet-creation-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloning a List in Python</title>
		<link>http://www.thenumber42.net/2008/04/14/cloning-a-list-in-python/</link>
		<comments>http://www.thenumber42.net/2008/04/14/cloning-a-list-in-python/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 21:42:32 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[clone]]></category>
		<category><![CDATA[list]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/?p=97</guid>
		<description><![CDATA[As far as I know there is no official way to clone a list in Python.  This is desirable at times because normal variable assignment of lists is just a reference copy.  For example:
&#160;
&#62;&#62;&#62; listA = &#91;'A', 'B', 'C', 'D'&#93;
&#62;&#62;&#62; listB = listA
&#62;&#62;&#62; listA
&#91;'A', 'B', 'C', 'D'&#93;
&#62;&#62;&#62; listB
&#91;'A', 'B', 'C', 'D'&#93;
&#62;&#62;&#62; listA.remove&#40;'C'&#41;
&#62;&#62;&#62; listA
&#91;'A', [...]]]></description>
			<content:encoded><![CDATA[<p>As far as I know there is no official way to clone a list in Python.  This is desirable at times because normal variable assignment of lists is just a reference copy.  For example:</p>
<pre class="python">&nbsp;
&gt;&gt;&gt; listA = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'C'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listB = listA
&gt;&gt;&gt; listA
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'C'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listB
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'C'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listA.<span style="color: black;">remove</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'C'</span><span style="color: black;">&#41;</span>
&gt;&gt;&gt; listA
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listB
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&nbsp;</pre>
<p>As you can see, B was assigned to reference the same list as A and removing something from A also removed it from B.</p>
<p>At times that is fine, however, sometimes you need a clone of the list so that changes in A do not reflect in B.  A very simple way to accomplish that is by using slicing.  Our example now becomes:</p>
<pre class="python">&nbsp;
&gt;&gt;&gt; listA = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'C'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listB = listA<span style="color: black;">&#91;</span>:<span style="color: black;">&#93;</span>
&gt;&gt;&gt; listA
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'C'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listB
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'C'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listA.<span style="color: black;">remove</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'C'</span><span style="color: black;">&#41;</span>
&gt;&gt;&gt; listA
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&gt;&gt;&gt; listB
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'A'</span>, <span style="color: #483d8b;">'B'</span>, <span style="color: #483d8b;">'C'</span>, <span style="color: #483d8b;">'D'</span><span style="color: black;">&#93;</span>
&nbsp;</pre>
<p>There we go, problem solved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2008/04/14/cloning-a-list-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Use JPype</title>
		<link>http://www.thenumber42.net/2008/03/31/how-to-use-jpype/</link>
		<comments>http://www.thenumber42.net/2008/03/31/how-to-use-jpype/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 18:41:11 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[jpype]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/2008/03/31/how-to-use-jpype/</guid>
		<description><![CDATA[Background
I love Python and my personal experience has shown that testers are about 4x more productive when using Python than when using Java.  However, at work I am a tester on a Java application.  I've been looking for a way to bridge that gap and allow me to write my tests in Python [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>I love Python and my personal experience has shown that testers are about 4x more productive when using Python than when using Java.  However, at work I am a tester on a Java application.  I've been looking for a way to bridge that gap and allow me to write my tests in Python but test a Java application.</p>
<p>I've looked into <a href="http://www.jython.org/Project/index.html">Jython</a> and while it had many advantages it has one major drawback that I can't live with: Jython only implements Python 2.2.  Most of the time this is fine, but there are times where I use Python 2.4 or 2.5 features and don't want to create a workaround just so I can use an older Python standard.  If I had the money I would pay someone to bring Jython up to date.  But, that's not a possibility.</p>
<p>I did find another alternative that so far seems to work great.  It is still in development, but <a href="http://jpype.sourceforge.net/">JPype</a> seems to be working fairly well.  JPype differs in philosophy from Jython in a fundamental way: Jython is a complete reimplementation of Python in Java, whereas JPype is a bridge between CPython and native Java.</p>
<h2>Kicking The Tires</h2>
<p>This article is a "how to," so let's get down to business.  I'm going to create a Java class that I would like to access from Python.  Here is Java class:</p>
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> org.<span style="color: #006600;">wg3i</span>.<span style="color: #006600;">test</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Test <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> msg;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Test<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> speak<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> msg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setString<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> s<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	msg = s;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> getString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">return</span> msg;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>The class is simple enough, but it will illustrate the basic JPype usage.  For my testing I compiled this and placed it into a jar file.  Feel free to leave it as a class file if you wish.  I'll show you how to deal with both situations below.</p>
<p>For reference, here is my ant build file:<br />
<font face="courier"><br />
&lt;?xml&nbsp;version=&quot;1.0&quot;?&gt;<br />
&lt;project&nbsp;name=&quot;TestProject&quot;<br />
	&nbsp;basedir=&quot;.&quot;<br />
	&nbsp;default=&quot;jar&quot;&gt;</p>
<p>&nbsp;&nbsp;&lt;property&nbsp;name=&quot;src.dir&quot;&nbsp;value=&quot;src&quot;/&gt;<br />
&nbsp;&nbsp;&lt;property&nbsp;name=&quot;build.dir&quot;&nbsp;value=&quot;build&quot;/&gt;<br />
&nbsp;&nbsp;&lt;property&nbsp;name=&quot;classes.dir&quot;&nbsp;value=&quot;${build.dir}/classes&quot;/&gt;<br />
&nbsp;&nbsp;&lt;property&nbsp;name=&quot;jar.dir&quot;&nbsp;value=&quot;${build.dir}/jar&quot;/&gt;<br />
&nbsp;<br />
&nbsp;&nbsp;&lt;target&nbsp;name=&quot;clean&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;delete&nbsp;dir=&quot;build&quot;/&gt;<br />
&nbsp;&nbsp;&lt;/target&gt;<br />
&nbsp;<br />
&nbsp;&nbsp;&lt;target&nbsp;name=&quot;compile&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;mkdir&nbsp;dir=&quot;${classes.dir}&quot;/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;javac&nbsp;srcdir=&quot;${src.dir}&quot;&nbsp;destdir=&quot;${classes.dir}&quot;/&gt;<br />
&nbsp;&nbsp;&lt;/target&gt;<br />
&nbsp;<br />
&nbsp;&nbsp;&lt;target&nbsp;name=&quot;jar&quot;&nbsp;depends=&quot;compile&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;mkdir&nbsp;dir=&quot;${jar.dir}&quot;/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;jar&nbsp;destfile=&quot;${jar.dir}/${ant.project.name}.jar&quot;<br />
	&nbsp;basedir=&quot;${classes.dir}&quot;/&gt;<br />
&nbsp;&nbsp;&lt;/target&gt;<br />
&nbsp;<br />
&nbsp;&nbsp;&lt;target&nbsp;name=&quot;clean-build&quot;&nbsp;depends=&quot;clean,jar&quot;&gt;<br />
&nbsp;&nbsp;&lt;/target&gt;<br />
&lt;/project&gt;</font><br />
After creating a jar file you are ready to go.  Here is the Python code to utilize a jar file and create an instance of the Java class.</p>
<pre class="python">&nbsp;
<span style="color: #808080; font-style: italic;"># Simple little JPype test.  Note: This test assumes</span>
<span style="color: #808080; font-style: italic;"># that the jar file is in the build/jar directory</span>
<span style="color: #808080; font-style: italic;"># relative to the current directory</span>
<span style="color: #ff7700;font-weight:bold;">import</span> jpype
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>
&nbsp;
jarpath = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">'build/jar'</span><span style="color: black;">&#41;</span>
jpype.<span style="color: black;">startJVM</span><span style="color: black;">&#40;</span>jpype.<span style="color: black;">getDefaultJVMPath</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;-Djava.ext.dirs=%s&quot;</span> % jarpath<span style="color: black;">&#41;</span>
Test = jpype.<span style="color: black;">JClass</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'org.wg3i.test.Test'</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># get the class</span>
t = Test<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># create an instance of the class</span>
t.<span style="color: black;">speak</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;This is a test message&quot;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># try to call one of the class methods</span>
t.<span style="color: black;">setString</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello, World&quot;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># set a string</span>
s = t.<span style="color: black;">getString</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># get the string back</span>
<span style="color: #ff7700;font-weight:bold;">print</span> s
jpype.<span style="color: black;">shutdownJVM</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<p>In a nutshell that's it.  I promised to show you how to initialize JPype when you have class files and not jar files.  Here's a Python example that shows that  This example also shows the use of the JPackage method, which gets a <em>package</em>, not a class.</p>
<pre class="python">&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> jpype
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>
&nbsp;
classpath = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">'build/classes'</span><span style="color: black;">&#41;</span>
jpype.<span style="color: black;">startJVM</span><span style="color: black;">&#40;</span>jpype.<span style="color: black;">getDefaultJVMPath</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;-Djava.class.path=%s&quot;</span> % classpath<span style="color: black;">&#41;</span>
testPkg = jpype.<span style="color: black;">JPackage</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'org'</span><span style="color: black;">&#41;</span>.<span style="color: black;">wg3i</span>.<span style="color: #dc143c;">test</span>  <span style="color: #808080; font-style: italic;"># get the package</span>
Test = testPkg.<span style="color: black;">Test</span> <span style="color: #808080; font-style: italic;"># get the class</span>
t = Test<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># create an instance of the class</span>
t.<span style="color: black;">speak</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;This is a test message&quot;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># try to call one of the class methods</span>
t.<span style="color: black;">setString</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello, World&quot;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># set a string</span>
s = t.<span style="color: black;">getString</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># get the string back</span>
<span style="color: #ff7700;font-weight:bold;">print</span> s
jpype.<span style="color: black;">shutdownJVM</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>
<h2>Conclusion</h2>
<p>There are many things I have not covered, such as passing arrays back and forth, types other than strings, exceptions, etc.  However, this should be enough to get you started using JPype.  I'd be interested in hearing your own experiences or suggestions.</p>
<div class="link-summarizer">Link Summary
<ul>
<li><a href='http://www.jython.org/Project/index.html'>http://www.jython.org/Project/index.html</a></li><li><a href='http://jpype.sourceforge.net/'>http://jpype.sourceforge.net/</a></li><li><a href='http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky'>http://www.google.com...27m%20Feeling%20Lucky</a></li><li><a href='http://www.google.com/search?hl=en&amp;q=allinurl%3ASystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky'>http://www.google.com...27m%20Feeling%20Lucky</a></li>
</ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2008/03/31/how-to-use-jpype/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Python Dataflow Programming</title>
		<link>http://www.thenumber42.net/2008/03/27/python-dataflow-programming/</link>
		<comments>http://www.thenumber42.net/2008/03/27/python-dataflow-programming/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 19:53:17 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[dataflow]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/2008/03/27/python-dataflow-programming/</guid>
		<description><![CDATA[Dataflow programming is something new to me.  Lately I've been looking up articles and information about this programming paradigm.  In a sense I suppose that I am familiar with the concepts.  In Linux I use the pipe "&#124;" a lot to pump data from one program to another.  Each program in the stage alters the [...]]]></description>
			<content:encoded><![CDATA[<p>Dataflow programming is something new to me.  Lately I've been looking up articles and information about this programming paradigm.  In a sense I suppose that I am familiar with the concepts.  In Linux I use the pipe "|" a lot to pump data from one program to another.  Each program in the stage alters the data in some way.  This is basically what dataflow programming is all about -- piping data through a system of small blocks, with each block altering the data in some way.</p>
<p>In doing my searches I came across an interesting Python package that allows you to do basic dataflow programming.  <a href="http://www.thensys.com/index.php?title=dataflow_programming&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1">This article</a> by the author of <em>zflow</em> covers the basic usage and concepts of the package and dataflow programming in general.  I am interested to see if this package keeps evolving.  Now, I just need to figure out a good application in software testing for dataflow programming.  Any ideas?</p>
<div class="link-summarizer">Link Summary
<ul>
<li><a href='http://www.thensys.com/index.php?title=dataflow_programming&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1'>http://www.thensys.co...c=1&amp;tb=1&amp;pb=1</a></li>
</ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2008/03/27/python-dataflow-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating PDF&#8217;s in Python</title>
		<link>http://www.thenumber42.net/2006/07/25/creating-pdfs-in-python/</link>
		<comments>http://www.thenumber42.net/2006/07/25/creating-pdfs-in-python/#comments</comments>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[test plan]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/2006/07/25/creating-pdfs-in-python/</guid>
		<description><![CDATA[Whatever your role or occupation there are doubtless times where you need to write a report.  Most of the reports that I turn in are unique and need to be manually generated.  However, my weekly test status report is pretty much the same every week and basically its just the stats that change.
Poking [...]]]></description>
			<content:encoded><![CDATA[<p>Whatever your role or occupation there are doubtless times where you need to write a report.  Most of the reports that I turn in are unique and need to be manually generated.  However, my weekly test status report is pretty much the same every week and basically its just the stats that change.</p>
<p>Poking around on the web I found <a href="http://www.reportlab.org">Report Lab</a>, an excellent package for creating PDF's with a Python API.</p>
<div class="link-summarizer">Link Summary
<ul>
<li><a href='http://www.reportlab.org'>http://www.reportlab.org</a></li>
</ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2006/07/25/creating-pdfs-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Results Comparison in PyFIT Fixtures</title>
		<link>http://www.thenumber42.net/2006/06/26/results-comparison-in-pyfit-fixtures/</link>
		<comments>http://www.thenumber42.net/2006/06/26/results-comparison-in-pyfit-fixtures/#comments</comments>
		<pubDate>Mon, 26 Jun 2006 22:31:00 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[fit]]></category>
		<category><![CDATA[pyfit]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/2006/06/26/results-comparison-in-pyfit-fixtures/</guid>
		<description><![CDATA[I'm not sure if this is the intended behavior or not, but I found a "feature" in PyFIT that had me smashing the keyboard with my face.  According to the PyFIT documentation you should be able to create a table like this:

&#124;TestClass&#124;
&#124;InputString    &#124;OutputNum    &#124;
&#124;Hello World    [...]]]></description>
			<content:encoded><![CDATA[<p>I'm not sure if this is the intended behavior or not, but I found a "feature" in PyFIT that had me smashing the keyboard with my face.  According to the PyFIT documentation you should be able to create a table like this:</p>
<pre>
|TestClass|
|InputString    |OutputNum    |
|Hello World    |&gt;10       |
|Python is cool!|1 &lt; _ &lt; 100|
</pre>
<p>The value returned by the OutputNum method of TestClass should result in a comparison and the cell being highlighted green or red depending on a pass or fail.  What the documents don't seem to point out is that doing the comparison on a field declared as an Integer in the _typeDict results in strange looking errors.  After much frustration, checking and rechecking my syntax, I tried changing that number to a Float and it worked.  So, Floats can be compared and have ranges and Integers can't.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2006/06/26/results-comparison-in-pyfit-fixtures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running FitNesse tests from the command line with PyFIT</title>
		<link>http://www.thenumber42.net/2006/06/21/running-fitnesse-tests-from-the-command-line-with-pyfit/</link>
		<comments>http://www.thenumber42.net/2006/06/21/running-fitnesse-tests-from-the-command-line-with-pyfit/#comments</comments>
		<pubDate>Thu, 22 Jun 2006 00:26:00 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[fit]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[pyfit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.thenumber42.net/2006/06/21/running-fitnesse-tests-from-the-command-line-with-pyfit/</guid>
		<description><![CDATA[I'm really starting to get into this whole FIT/FitNesse thing.  Creating test cases is now easy and my managers love the HTML documentation and results that come out of the tools.  Until now I've just been using FitNesse, but thanks to the hard work of Grig Gheorghiu and John Roth (the PyFIT author) [...]]]></description>
			<content:encoded><![CDATA[<p>I'm really starting to get into this whole <a href="http://fit.c2.com/">FIT</a>/<a href="http://fitnesse.org/">FitNesse</a> thing.  Creating test cases is now easy and my managers love the HTML documentation and results that come out of the tools.  Until now I've just been using FitNesse, but thanks to the hard work of <a href="http://agiletesting.blogspot.com/">Grig Gheorghiu</a> and John Roth (the PyFIT author) here's how you can run all of your FitNesse tests and export the results to static HTML web pages: <a href="http://agiletesting.blogspot.com/2006/02/running-fitnesse-tests-from-command.html">Agile Testing: Running FitNesse tests from the command line with PyFIT</a></p>
<div class="link-summarizer">Link Summary
<ul>
<li><a href='http://fit.c2.com/'>http://fit.c2.com/</a></li><li><a href='http://fitnesse.org/'>http://fitnesse.org/</a></li><li><a href='http://agiletesting.blogspot.com/'>http://agiletesting.blogspot.com/</a></li><li><a href='http://agiletesting.blogspot.com/2006/02/running-fitnesse-tests-from-command.html'>http://agiletesting.b...sts-from-command.html</a></li>
</ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.thenumber42.net/2006/06/21/running-fitnesse-tests-from-the-command-line-with-pyfit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
