<?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>C L Snyder &#187; Python</title>
	<atom:link href="http://www.clsnyder.com/WordPress/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.clsnyder.com/WordPress</link>
	<description>Kaizen with Sprezzatura</description>
	<lastBuildDate>Mon, 06 Feb 2012 22:52:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python Google Stock Quotes</title>
		<link>http://www.clsnyder.com/WordPress/2008/06/06/python-google-stock-quotes/</link>
		<comments>http://www.clsnyder.com/WordPress/2008/06/06/python-google-stock-quotes/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 22:38:25 +0000</pubDate>
		<dc:creator>clsnyder</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.clsnyder.com/WordPress/?p=215</guid>
		<description><![CDATA[import urllib import re def get_quote(symbol): base_url = 'http://finance.google.com/finance?q=' content = urllib.urlopen(base_url + symbol).read() m = re.search('class="pr".*?>(.*?)]]></description>
			<content:encoded><![CDATA[<pre class="prettyprint">
import urllib
import re

def get_quote(symbol):
    base_url = 'http://finance.google.com/finance?q='
    content = urllib.urlopen(base_url + symbol).read()
    m = re.search('class="pr".*?>(.*?)<', content)
    if m:
        quote = m.group(1)
        print symbol + "   " + quote
    else:
        quote = 'no quote available for: ' + symbol
    return quote

items = ["AAPL","GOOG","ININ","EWH","IAU"]
for n in items:
    get_quote(n)
raw_input( )
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.clsnyder.com/WordPress/2008/06/06/python-google-stock-quotes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python File Renamer</title>
		<link>http://www.clsnyder.com/WordPress/2008/05/17/python-file-renamer/</link>
		<comments>http://www.clsnyder.com/WordPress/2008/05/17/python-file-renamer/#comments</comments>
		<pubDate>Sat, 17 May 2008 23:46:57 +0000</pubDate>
		<dc:creator>clsnyder</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.clsnyder.com/WordPress/?p=165</guid>
		<description><![CDATA[import os illegal = list('''!"#$%&#038;\'()*+,/:;?@[\\]^_`{&#124;}~''') repl = " " for root,dir,files in os.walk(os.getcwd()): for fi in files: for ill in illegal: if ill in fi: print "found ", os.path.join(root,fi) newname = fi.replace(ill,repl) os.rename( os.path.join(root,fi) , os.path.join(root,newname) )]]></description>
			<content:encoded><![CDATA[<pre class="prettyprint">
import os
illegal = list('''!"#$%&#038;\'()*+,/:;<=>?@[\\]^_`{|}~''')
repl = " "
for root,dir,files in os.walk(os.getcwd()):
    for fi in files:
       for ill in illegal:
            if ill in fi:
                print "found ",  os.path.join(root,fi)
                newname = fi.replace(ill,repl)
                os.rename( os.path.join(root,fi) , os.path.join(root,newname) )
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.clsnyder.com/WordPress/2008/05/17/python-file-renamer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python text to dictionary</title>
		<link>http://www.clsnyder.com/WordPress/2007/09/11/python-text-to-dictionary/</link>
		<comments>http://www.clsnyder.com/WordPress/2007/09/11/python-text-to-dictionary/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 23:45:42 +0000</pubDate>
		<dc:creator>clsnyder</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.clsnyder.com/WordPress/?p=78</guid>
		<description><![CDATA[&#160; #Takes a text file of items and numbers on each line and returns a dictionary of them # list.txt is a file that contains the following lines: Apples 34 Bananas 10 Oranges 56 mystring = file.read&#40;&#41; mylist = mystring.split&#40;'\n'&#41; &#8230; <a href="http://www.clsnyder.com/WordPress/2007/09/11/python-text-to-dictionary/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">#Takes a text file of items and numbers on each line and returns a dictionary of them</span>
<span style="color: #808080; font-style: italic;"># list.txt is a file that contains the following lines: Apples 34 Bananas 10 Oranges 56</span>
mystring = <span style="color: #008000;">file</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
mylist = mystring.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span>
mydict = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
mydict<span style="color: black;">&#91;</span>l<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> = l<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #808080; font-style: italic;">#mydict yields {'Apples': '34', 'Oranges': '56', 'Bananas': '10'}</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.clsnyder.com/WordPress/2007/09/11/python-text-to-dictionary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Cellular automata</title>
		<link>http://www.clsnyder.com/WordPress/2007/09/11/python-cellular-automata/</link>
		<comments>http://www.clsnyder.com/WordPress/2007/09/11/python-cellular-automata/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 23:43:52 +0000</pubDate>
		<dc:creator>clsnyder</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.clsnyder.com/WordPress/?p=76</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 &#8230; <a href="http://www.clsnyder.com/WordPress/2007/09/11/python-cellular-automata/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># CellularAutomata.py: Wolfram-style cellular automata in Python</span>
<span style="color: #808080; font-style: italic;"># Options:</span>
<span style="color: #808080; font-style: italic;"># -h #  Use a screen of height # for the simulation</span>
<span style="color: #808080; font-style: italic;"># -w #  Use a screen of width # for the simulation</span>
<span style="color: #808080; font-style: italic;"># -r      Use a random initial row (rather than the standard single 1 in the middle)</span>
<span style="color: #808080; font-style: italic;"># -R #  Use rule # for the simulation</span>
<span style="color: #483d8b;">&quot;&quot;&quot;
import getopt,sys
from random import randint
def ca_data(height,width,dorandom,rulenum):
    # Create the first row, either randomly, or with a single 1
    if dorandom:
        first_row = [randint(0,1) for i in range(width)]
    else:
        first_row = [0]*width
        first_row[width/2] = 1
    results = [first_row]
    # Convert the rule number to a list of outcomes.
    rule = [(rulenum/pow(2,i)) % 2 for i in range(8)]
    for i in range(height-1):
        data = results[-1]
        # Determine the new row based on the old data. We first make an
        #  integer out of the value of the old row and its two neighbors
        #  and then use that value to get the outcome from the table we
        #  computed earlier
        new = [rule[4*data[(j-1)%width]+2*data[j]+data[(j+1)%width]]
               for j in range(width)]
        results.append(new)
    return results
def pil_render(data,height,width,fname=&quot;bs.png&quot;):
    import Image, ImageDraw
    img = Image.new(&quot;RGB&quot;,(width,height),(255,255,255))
    draw = ImageDraw.Draw(img)
    for y in range(height):
        for x in range(width):
            if data[y][x]: draw.point((x,y),(0,0,0))
    img.save(fname,&quot;PNG&quot;)
    return
def main():
    opts,args = getopt.getopt(sys.argv[1:],‘h:w:rR:’)
    height = 500
    width = 500
    dorandom = 0
    rule = 22
    for key,val in opts:
        if key == ‘-h’: height = int(val)
        if key == ‘-w’: width = int(val)
        if key == ‘-r’: dorandom = 1
        if key == ‘-R’: rule = int(val)
    data = ca_data(height,width,dorandom,rule)
    pil_render(data,height,width)
    return
if __name__ == ‘__main__’: main()</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.clsnyder.com/WordPress/2007/09/11/python-cellular-automata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Histogram</title>
		<link>http://www.clsnyder.com/WordPress/2007/09/11/python-histogram/</link>
		<comments>http://www.clsnyder.com/WordPress/2007/09/11/python-histogram/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 23:41:40 +0000</pubDate>
		<dc:creator>clsnyder</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.clsnyder.com/WordPress/?p=74</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 A=&#91;7,8,9,5,3,2,1,3,4,5,6,7,8,9,9,9,9,0,0,0,1,2,3&#93; def histogram&#40; A, flAsList=False &#41;: #Return histogram of values in array A.&#34;&#34;&#34; H = &#123;&#125; for val in A: H&#91;val&#93; = H.get&#40;val,0&#41; + 1 if flAsList: return &#8230; <a href="http://www.clsnyder.com/WordPress/2007/09/11/python-histogram/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">A=<span style="color: black;">&#91;</span><span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">8</span>,<span style="color: #ff4500;">9</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span>,<span style="color: #ff4500;">6</span>,<span style="color: #ff4500;">7</span>,<span style="color: #ff4500;">8</span>,<span style="color: #ff4500;">9</span>,<span style="color: #ff4500;">9</span>,<span style="color: #ff4500;">9</span>,<span style="color: #ff4500;">9</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> histogram<span style="color: black;">&#40;</span> A, flAsList=<span style="color: #008000;">False</span> <span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;">#Return histogram of values in array A.&quot;&quot;&quot;</span>
    H = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> val <span style="color: #ff7700;font-weight:bold;">in</span> A:
        H<span style="color: black;">&#91;</span>val<span style="color: black;">&#93;</span> = H.<span style="color: black;">get</span><span style="color: black;">&#40;</span>val,<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> flAsList:
        <span style="color: #ff7700;font-weight:bold;">return</span> H.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> H
<span style="color: #808080; font-style: italic;"># Then the call is self-documenting:</span>
freq = histogram<span style="color: black;">&#40;</span>A<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> freq</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.clsnyder.com/WordPress/2007/09/11/python-histogram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jumble.py</title>
		<link>http://www.clsnyder.com/WordPress/2006/07/08/jumblepy/</link>
		<comments>http://www.clsnyder.com/WordPress/2006/07/08/jumblepy/#comments</comments>
		<pubDate>Sun, 09 Jul 2006 02:49:33 +0000</pubDate>
		<dc:creator>clsnyder</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.clsnyder.com/WordPress/?p=13</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #!/bin/env python def find_jumble&#40;jumble, word_file='/users/charleslsnyder/dictionary.txt'&#41;: #you have to reset the word file to your dictionary and path sorted_jumble = sort_chars&#40;jumble&#41; for dictword &#8230; <a href="http://www.clsnyder.com/WordPress/2006/07/08/jumblepy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">def</span> find_jumble<span style="color: black;">&#40;</span>jumble, word_file=<span style="color: #483d8b;">'/users/charleslsnyder/dictionary.txt'</span><span style="color: black;">&#41;</span>: 
<span style="color: #808080; font-style: italic;">#you have to reset the word file to your dictionary and path</span>
sorted_jumble = sort_chars<span style="color: black;">&#40;</span>jumble<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> dictword <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>word_file, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>.<span style="color: black;">xreadlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
<span style="color: #ff7700;font-weight:bold;">if</span> sorted_jumble == sort_chars<span style="color: black;">&#40;</span>dictword<span style="color: black;">&#41;</span>:
<span style="color: #ff7700;font-weight:bold;">yield</span> dictword
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> sort_chars<span style="color: black;">&#40;</span>word<span style="color: black;">&#41;</span>:
w = <span style="color: #008000;">list</span><span style="color: black;">&#40;</span>word.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
w.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">return</span> w
&nbsp;
<span style="color: #ff7700;font-weight:bold;">while</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
inp = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Enter word: &quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> inp: <span style="color: #ff7700;font-weight:bold;">break</span>
<span style="color: #ff7700;font-weight:bold;">for</span> ans <span style="color: #ff7700;font-weight:bold;">in</span> find_jumble<span style="color: black;">&#40;</span>inp<span style="color: black;">&#41;</span>:
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answer = &quot;</span>, ans</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.clsnyder.com/WordPress/2006/07/08/jumblepy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

