<?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>spechal.com &#187; Python</title>
	<atom:link href="http://spechal.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://spechal.com</link>
	<description>[spesh-uhl]</description>
	<lastBuildDate>Sat, 24 Dec 2011 03:41:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Resizing and recoloring images with Python</title>
		<link>http://spechal.com/2011/03/20/resizing-and-recoloring-images-with-python/</link>
		<comments>http://spechal.com/2011/03/20/resizing-and-recoloring-images-with-python/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 07:09:51 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=240</guid>
		<description><![CDATA[import Image # I have the power! &#160; theFile = &#34;foo.png&#34; # the file to start with &#160; img = Image.open&#40;theFile&#41; # open the image resized = img.resize&#40;&#40;75,75&#41;&#41; # resize the image r, g, b, alpha = resized.split&#40;&#41; # get &#8230; <a href="http://spechal.com/2011/03/20/resizing-and-recoloring-images-with-python/">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;"><span style="color: #ff7700;font-weight:bold;">import</span> Image <span style="color: #808080; font-style: italic;"># I have the power!</span>
&nbsp;
theFile = <span style="color: #483d8b;">&quot;foo.png&quot;</span> <span style="color: #808080; font-style: italic;"># the file to start with</span>
&nbsp;
img = Image.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>theFile<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># open the image</span>
resized = img.<span style="color: black;">resize</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">75</span>,<span style="color: #ff4500;">75</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># resize the image</span>
r, g, b, alpha = resized.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># get the RGBA data</span>
&nbsp;
newImage = Image.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>resized.<span style="color: black;">mode</span>, resized.<span style="color: black;">size</span>, <span style="color: #483d8b;">&quot;black&quot;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># make a new image</span>
newImage.<span style="color: black;">paste</span><span style="color: black;">&#40;</span>resized, mask=alpha<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># copy the old to the new</span>
newImage.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;out.png&quot;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># save it</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Done&quot;</span> <span style="color: #808080; font-style: italic;"># Yay!</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2011/03/20/resizing-and-recoloring-images-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python MySQL Associative Array</title>
		<link>http://spechal.com/2009/11/27/python-mysql-associative-array/</link>
		<comments>http://spechal.com/2009/11/27/python-mysql-associative-array/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 23:26:04 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=87</guid>
		<description><![CDATA[By default, the MySQLdb module to access a MySQL database returns the data as an integer indexed array. Sometimes this is not desirable and an associative array is preferred, such as the mysql_fetch_assoc function in PHP. In addition, we will &#8230; <a href="http://spechal.com/2009/11/27/python-mysql-associative-array/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>By default, the MySQLdb module to access a MySQL database returns the data as an integer indexed array.  Sometimes this is not desirable and an associative array is preferred, such as the mysql_fetch_assoc function in PHP.  In addition, we will be using the pprint module which is similar PHP&#8217;s print_r</p>
<p>Here is the Python equivalent:</p>
<pre class="python" name="code">
import MySQLdb
import pprint
# connect to the database here
db = MySQLdb.connect(...)
c = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
query = "SELECT `name`, `address` FROM `table`"
c.execute(query)
rows = c.fetchall()
c.close()
pprint.pprint(rows) # i.e. print_r($rows)
</pre>
<p>Hope that helps someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/27/python-mysql-associative-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python emulate mouse click in Windows</title>
		<link>http://spechal.com/2009/11/20/python-emulate-mouse-click-in-windows/</link>
		<comments>http://spechal.com/2009/11/20/python-emulate-mouse-click-in-windows/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 14:38:18 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=76</guid>
		<description><![CDATA[The following bit of code, which requires the win32api, simulates a mouse click using Python under the Windows OS. import win32api, win32con def click(x,y): win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0) click(100, 100) # simulate mouse &#8230; <a href="http://spechal.com/2009/11/20/python-emulate-mouse-click-in-windows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The following bit of code, which requires the win32api, simulates a mouse click using Python under the Windows OS.</p>
<pre class="python" name="code">
import win32api, win32con

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)

click(100, 100) # simulate mouse click at 100px, 100px
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/20/python-emulate-mouse-click-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Print Screen and Save Image in Windows</title>
		<link>http://spechal.com/2009/11/20/python-print-screen-and-save-image-in-windows/</link>
		<comments>http://spechal.com/2009/11/20/python-print-screen-and-save-image-in-windows/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 00:07:14 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=70</guid>
		<description><![CDATA[So you need to do a &#8220;Print Screen&#8221; and save the image in the clipboard huh?  I had that exact need too.  Let me save you a few hours of trouble and tell you that the win32clipboard does not yet &#8230; <a href="http://spechal.com/2009/11/20/python-print-screen-and-save-image-in-windows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So you need to do a &#8220;Print Screen&#8221; and save the image in the clipboard huh?  I had that exact need too.  Let me save you a few hours of trouble and tell you that the win32clipboard does not yet have the ability to return the contents of the clipboard when the contents are BITMAP, despite the CF_BITMAP constant.</p>
<p>How do you do it then?  I was wondering the same thing.  Behold, PIL.  PIL, the Python Image Library, saved me from a massive headache.</p>
<p>Here is the code to take a screen shot and save it.  You will need the win32api and PIL libraries.</p>
<pre class="python">import win32api, win32con, ImageGrab
win32api.keybd_event(win32con.VK_SNAPSHOT, 1)
im = ImageGrab.grabclipboard()
im.save("screenshot.jpg", "JPEG")
</pre>
<p>Now wasn&#8217;t that easy!</p>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/20/python-print-screen-and-save-image-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Abstract Snow Art using PyGame</title>
		<link>http://spechal.com/2009/11/17/python-abstract-snow-art/</link>
		<comments>http://spechal.com/2009/11/17/python-abstract-snow-art/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 02:27:12 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Abstract]]></category>
		<category><![CDATA[Art]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=56</guid>
		<description><![CDATA[# # Abstract Random Snow Art # Copyright 2009 Travis Crowder # travis.crowder@spechal.com # Published under the MIT License # import pygame, sys, random from pygame.color import THECOLORS pygame.init() screen = pygame.display.set_mode([640,480]) screen.fill([0,0,0]) for i in range(1, 2500): top = &#8230; <a href="http://spechal.com/2009/11/17/python-abstract-snow-art/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<pre class="python">#
#   Abstract Random Snow Art
#   Copyright 2009 Travis Crowder
#   travis.crowder@spechal.com
#   Published under the MIT License
#
import pygame, sys, random
from pygame.color import THECOLORS

pygame.init()

screen = pygame.display.set_mode([640,480])
screen.fill([0,0,0])

for i in range(1, 2500):
    top = random.randint(2, 478)
    left = random.randint(2, 638)
    color_name = random.choice(THECOLORS.keys())
    color = THECOLORS[color_name]
    pygame.draw.rect(screen, color, [left, top, 1, 1], 1)
pygame.display.flip()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/17/python-abstract-snow-art/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Abstract Box Art using PyGame</title>
		<link>http://spechal.com/2009/11/17/python-abstract-box-art/</link>
		<comments>http://spechal.com/2009/11/17/python-abstract-box-art/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 02:21:35 +0000</pubDate>
		<dc:creator>Spechal</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Abstract]]></category>
		<category><![CDATA[Art]]></category>

		<guid isPermaLink="false">http://spechal.com/?p=53</guid>
		<description><![CDATA[# # Abstract Random Box Art # Copyright 2009 Travis Crowder # travis.crowder@spechal.com # Published under the MIT License # import pygame, sys, random from pygame.color import THECOLORS pygame.init() screen = pygame.display.set_mode([640,480]) screen.fill([0,0,0]) for i in range(1, 100): width = &#8230; <a href="http://spechal.com/2009/11/17/python-abstract-box-art/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<pre class="python">#
#   Abstract Random Box Art
#   Copyright 2009 Travis Crowder
#   travis.crowder@spechal.com
#   Published under the MIT License
#
import pygame, sys, random
from pygame.color import THECOLORS

pygame.init()

screen = pygame.display.set_mode([640,480])
screen.fill([0,0,0])

for i in range(1, 100):
    width = random.randint(0, 250)
    height = random.randint(0, 250)
    top = random.randint(5, 435)
    left = random.randint(5, 375)
    color_name = random.choice(THECOLORS.keys())
    color = THECOLORS[color_name]
    line_width = random.randint(1,3)
    pygame.draw.rect(screen, color, [left, top, width, height], line_width)
pygame.display.flip()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://spechal.com/2009/11/17/python-abstract-box-art/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

