<?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>comp-e.com &#187; python</title>
	<atom:link href="http://comp-e.com/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://comp-e.com</link>
	<description>Computer Engineering</description>
	<lastBuildDate>Fri, 13 May 2011 06:11:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Python &#8211; Filter directory contents</title>
		<link>http://comp-e.com/python-filter-directory-contents</link>
		<comments>http://comp-e.com/python-filter-directory-contents#comments</comments>
		<pubDate>Mon, 28 Mar 2011 02:55:23 +0000</pubDate>
		<dc:creator>COMP-E</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://comp-e.com/?p=158</guid>
		<description><![CDATA[short and sweet, this python snippet will return a list containing your filtered directory import re import os filter = ".*" + searchstr + ".*" m = re.compile(filter,re.I) #if you want to ignore case use re.I, otherwise remove it filter(m.search,os.listdir(os.getcwd())) &#8230; <a href="http://comp-e.com/python-filter-directory-contents">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>short and sweet, this python snippet will return a list containing your filtered directory </p>
<p><code><br />
import re<br />
import os</p>
<p>filter = ".*" + searchstr + ".*"<br />
m = re.compile(filter,re.I) #if you want to ignore case use re.I, otherwise remove it<br />
filter(m.search,os.listdir(os.getcwd()))</p>
<p>#that's it, you can see that the reason for compiling the regex is so you can use m.search as a function pointer which accepts the list of all items in the directory<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://comp-e.com/python-filter-directory-contents/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python &#8211; Use regex to split hyphenated words</title>
		<link>http://comp-e.com/python-use-regex-to-split-hyphenated-words</link>
		<comments>http://comp-e.com/python-use-regex-to-split-hyphenated-words#comments</comments>
		<pubDate>Mon, 28 Mar 2011 02:41:17 +0000</pubDate>
		<dc:creator>COMP-E</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://comp-e.com/?p=154</guid>
		<description><![CDATA[I was asked this question on stackoverflow, and figured I&#8217;d repost it here since I wrote it after all. s = "-this is. A - sentence;one-word what's" re.findall("\w+-\w+&#124;[\w']+",s) result: ['this', 'is', 'A', 'sentence', 'one-word', "what's"] make sure you notice that &#8230; <a href="http://comp-e.com/python-use-regex-to-split-hyphenated-words">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was asked this question on stackoverflow, and figured I&#8217;d repost it here since I wrote it after all.</p>
<p><code><br />
s = "-this is. A - sentence;one-word what's"<br />
re.findall("\w+-\w+|[\w']+",s)<br />
</code></p>
<p>result: ['this', 'is', 'A', 'sentence', 'one-word', "what's"]</p>
<p>make sure you notice that the correct ordering is to look for hypenated words first!</p>
]]></content:encoded>
			<wfw:commentRss>http://comp-e.com/python-use-regex-to-split-hyphenated-words/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python &#8211; Chunk string or data buffer</title>
		<link>http://comp-e.com/python-chunk-string-or-data-buffer</link>
		<comments>http://comp-e.com/python-chunk-string-or-data-buffer#comments</comments>
		<pubDate>Mon, 28 Mar 2011 02:33:16 +0000</pubDate>
		<dc:creator>COMP-E</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://comp-e.com/?p=148</guid>
		<description><![CDATA[I was disappointed that there was no good way to chunk up data for string formatting or packetzing UDP data. After a bit of thought, and a desire to avoid using python code to do loops, I came up with &#8230; <a href="http://comp-e.com/python-chunk-string-or-data-buffer">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was disappointed that there was no good way to chunk up data for string formatting or packetzing UDP data.  After a bit of thought, and a desire to avoid using python code to do loops, I came up with a nice simple regex-based solution.<br />
<code><br />
import re<br />
buff = #some data buffer<br />
m = re.compile(r'.{##}|.+',re.S)<br />
chunks = m.findall(buff)</p>
<p>example:<br />
>>> import re<br />
>>> m = re.compile(r'.{5}|.*',re.S)<br />
>>> data = "HELLO_WORLD_HOW_ARE_YOU"<br />
>>> m.findall(data)<br />
['HELLO', '_WORL', 'D_HOW', '_ARE_', 'YOU']<br />
</code></p>
<p>I would assume that this is the most efficient way to do this, as it uses underlying c functions, and there&#8217;s nothing better than zippy python : )</p>
]]></content:encoded>
			<wfw:commentRss>http://comp-e.com/python-chunk-string-or-data-buffer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python &#8211; Convert 16bit image to 24bit image 565 to 888</title>
		<link>http://comp-e.com/python-convert-16bit-image-to-24bit-image-565-to-888</link>
		<comments>http://comp-e.com/python-convert-16bit-image-to-24bit-image-565-to-888#comments</comments>
		<pubDate>Mon, 28 Mar 2011 02:12:34 +0000</pubDate>
		<dc:creator>COMP-E</dc:creator>
				<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[comp-e]]></category>
		<category><![CDATA[image processing]]></category>
		<category><![CDATA[numpy]]></category>
		<category><![CDATA[pil]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://comp-e.com/?p=139</guid>
		<description><![CDATA[Doing the following is much better than using putpixel and a for loop, as numpy uses c-functions. The actual execution speed is about .3 seconds faster on a 240&#215;320 RGBA image. import numpy as np arr = np.fromstring(buff,dtype=np.uint16).astype(np.uint32) arr = &#8230; <a href="http://comp-e.com/python-convert-16bit-image-to-24bit-image-565-to-888">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Doing the following is much better than using putpixel and a for loop, as numpy uses c-functions.  The actual execution speed is about .3 seconds faster on a 240&#215;320 RGBA image.</p>
<p><code><br />
import numpy as np<br />
arr = np.fromstring(buff,dtype=np.uint16).astype(np.uint32)<br />
arr = 0xFF000000 + ((arr &amp; 0xF800) &gt;&gt; 8 ) + ((arr &amp; 0x07E0) &lt;&lt; 5) + ((arr &amp; 0x001F) &lt;&lt; 19)<br />
return Image.frombuffer('RGBA', (xdim,ydim), arr, 'raw', 'RGBA', 0, 1)<br />
</code></p>
<p>While it may seem like an odd bit shift, stuffing the channels into an int requires that it get stuffed as  (most significant bit) ABGR (least significant bit).  If you were to use the PIL call to putpixel, it would get stuffed as RGBA.</p>
]]></content:encoded>
			<wfw:commentRss>http://comp-e.com/python-convert-16bit-image-to-24bit-image-565-to-888/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pythons in the &#8216;C&#8217;ircus</title>
		<link>http://comp-e.com/pythons-in-the-circus</link>
		<comments>http://comp-e.com/pythons-in-the-circus#comments</comments>
		<pubDate>Thu, 06 Aug 2009 06:39:59 +0000</pubDate>
		<dc:creator>COMP-E</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[comp-e]]></category>
		<category><![CDATA[forum]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://comp-e.com/?p=131</guid>
		<description><![CDATA[Spiffy code that is.  Stubby has made a few contributions as of late, so check them out.  I will be ragging on him to put his battleship game up, but alas it seems it&#8217;s lacking comments so we&#8217;ll see how &#8230; <a href="http://comp-e.com/pythons-in-the-circus">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Spiffy code that is.  Stubby has made a few contributions as of late, so check them out.  I will be ragging on him to put his battleship game up, but alas it seems it&#8217;s lacking comments so we&#8217;ll see how long that takes.</p>
<p>I on the other hand, appologize for not tossing up any new coding examples.  As of late I&#8217;ve been rather busy but fear not for I&#8217;ve been dabbling in Python and have some fun stuff to share.  To give a bit of a hint, I&#8217;ve been playing with the Numpy module and have found it incredibly useful as it ties in exceptionally well with Matlab.  I also plan on making a mini program to poll USB for those of you who rely on antiquated RS232 and are left without an easy means of switching over : )</p>
<p>Lastly, I encourage more of you to join and contribute well documented examples to the site.  As always, there are no ads and questions will be answered without the arrogant charm of other such code collaborative sites</p>
]]></content:encoded>
			<wfw:commentRss>http://comp-e.com/pythons-in-the-circus/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

