<?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>techniQal support &#187; Python</title>
	<atom:link href="http://www.techniqal.com/blog/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techniqal.com/blog</link>
	<description>Software &#62; Technology &#62; Programming for Non-Engineers</description>
	<lastBuildDate>Wed, 07 Dec 2011 14:58:13 +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 3 File Read Write with Urllib</title>
		<link>http://www.techniqal.com/blog/2011/01/18/python-3-file-read-write-with-urllib/</link>
		<comments>http://www.techniqal.com/blog/2011/01/18/python-3-file-read-write-with-urllib/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 04:58:35 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[urllib]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/?p=304</guid>
		<description><![CDATA[This post is inspired by my previous post on utilizing urllib2 to download a sequence of files programatically. As you probably know, the transition from Python2.x to Python3 has left many people struggling to port their code, so I thought I would re-hash some of my old posts and provide Python3 versions of my code <a href='http://www.techniqal.com/blog/2011/01/18/python-3-file-read-write-with-urllib/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>This post is inspired by my <a href="http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/">previous post on utilizing urllib2</a> to download a sequence of files programatically. As you probably know, the transition from Python2.x to Python3 has left many people struggling to port their code, so I thought I would re-hash some of my old posts and provide Python3 versions of my code examples. One resource I found recently that really helped me is the <a href="http://diveintopython3.org/porting-code-to-python-3-with-2to3.html">online version of Mark Pilgrim&#8217;s &#8220;Dive into Python3&#8243;</a>, specifically the chapter on porting your 2.x code to Python3. </p>
<p>The example provided below outlines how to use the urllib library included within Python3 to download a sequence of image files along with comments to describe what is going on.</p>
<pre>
#import urllib request
import urllib.request
#import urllib error handling
from urllib.error import HTTPError,URLError

#function that downloads a file
def downloadFile(file_name,file_mode,base_url):
    #create the url
    url = base_url + file_name

    # Open the url
    try:
            f = urllib.request.urlopen(url)
            print("downloading ", url)

            # Open our local file for writing
            local_file = open(file_name, "w" + file_mode)
            #Write to our local file
            local_file.write(f.read())
            local_file.close()

    #handle errors
    except HTTPError as e:
            print("HTTP Error:",e.code , url)
    except URLError as e:
            print("URL Error:",e.reason , url)

# Set the range of images to 1-50.It says 51 because the
# range function never gets to the endpoint.
image_range = list(range(1,51))

# Iterate over image range
for index in image_range:
    base_url = 'http ://www.techniqal.com/'
    #create file name based on known pattern
    file_name =  str(index) + ".jpg"
    # Now download the image. If these were text files,
    # or other ascii types, just pass an empty string
    # for the second param ala stealStuff(file_name,'',base_url)
    downloadFile(file_name,"b",base_url)
</pre>
<p>The key things to learn about converting <a href="http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/">my old example</a> to the new are outlined below. This was a learning exercise for me, and will hopefully provide enough context for you to understand how to port your own code to Python3. </p>
<ul>
<li>
There are obvious changes on how to use Urllib vs the old Urllib2 methods. Take a peek at <a href="http://diveintopython3.org/">&#8220;Dive into Python3&#8243;</a> for more details. He does a much better job describing it than I ever could.
</li>
<li>
Print statements are now called as a function.</p>
<p>Python2:</p>
<pre>
print "My Variable is equal to " + myVariable
</pre>
<p>Python3:</p>
<pre>
print("My Variable is equal to ", myVariable)
</pre>
</li>
<li>Except blocks are handled differently when using a try/except.
<p>Python2:</p>
<pre>
except HTTPError, e:
		print "HTTP Error:",e.code , url
</pre>
<p>Python3:</p>
<pre>
except HTTPError as e:
		print("HTTP Error:",e.code , url)
</pre>
</li>
<li>
The range() function used to return a list , but now returns an iterator object. If you still want to get a list from the range function, see below.</p>
<p>Python2:</p>
<pre>
myRangeList = range(1,100)
</pre>
<p>Python3:</p>
<pre>
myRangeList = list(range(1,100))
</pre>
</li>
</ul>
<p>I&#8217;m not a software engineer by trade, so please excuse any syntax oddities. I appreciate any feedback, or more graceful ways to write this code. Leave them in the comments and I&#8217;ll happily update my example.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Python 3 File Read Write with Urllib on techniQal support',url: 'http://www.techniqal.com/blog/2011/01/18/python-3-file-read-write-with-urllib/',contentID: 'post-304',code: 'Dani8542',suggestTags: 'code,Python,urllib',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2011/01/18/python-3-file-read-write-with-urllib/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python File Read Write with Urllib2</title>
		<link>http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/</link>
		<comments>http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 23:01:49 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/</guid>
		<description><![CDATA[Update: Looking for how to download files using Python3 and urllib? Check out my post here . While checking out my great stats on Lijit recently, I started to see a pattern. I was able to determine that a large part of my Re-Search(search engine) traffic was coming from a post I did about reading <a href='http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Update: Looking for how to download files using Python3 and urllib? Check <a href="http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/">out my post here</a> .</p>
<p>While checking out my great <a href="http://www.lijit.com/users/damniel/stats#htab_searches" target="_blank">stats</a> on <a href="http://www.lijit.com">Lijit</a> recently, I started to see a pattern. I was able to determine that a large part of my Re-Search(search engine) traffic was coming from a post I did about <a href="http://www.techniqal.com/blog/2005/05/17/python-simple-file-read-and-write/" target="_blank">reading and writing to files in Python</a> back in&#160; 2005. In an effort to shamelessly attract more traffic on this topic, I have decided to flesh this post out a bit. </p>
<p>A common task that I run into both in my work life as well as my personal life, revolves around programmatically downloading content from the interwebs. This little code example will illustrate how to use urllib to download a file, and write/save the file contents locally. You may be saying to yourself “Self, can’t I do this in my favorite web browser??” . The answer is “YES”, but it’s a pain in the ass if you have more than 5 files you want to download.</p>
<p>Assume there are a set of images on your favorite website, and they are all named&#160; image1.jpg,image2.jpg,image3.jpg, etc. Now imagine there are 50 images using this naming convention.How do you download them all using python , without struggling to do it one image at a time in your browser? Look below!</p>
<p><a href="http://www.techniqal.com/blog/wp-content/uploads/2008/08/python4.png"><img title="python" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="63" alt="python" src="http://www.techniqal.com/blog/wp-content/uploads/2008/07/python-thumb.png" width="240" border="0" /></a><a href="http://www.techniqal.com/blog/wp-content/uploads/2008/08/python5.png"></a></p>
<pre># Let's create a function that downloads a file, and saves it locally.
# This function accepts a file name, a read/write mode(binary or text),
# and the base url.

def stealStuff(file_name,file_mode,base_url):
	from urllib2 import Request, urlopen, URLError, HTTPError

	#create the url and the request
	url = base_url + file_name
	req = Request(url)

	# Open the url
	try:
		f = urlopen(req)
		print &quot;downloading &quot; + url

		# Open our local file for writing
		local_file = open(file_name, &quot;w&quot; + file_mode)
		#Write to our local file
		local_file.write(f.read())
		local_file.close()

	#handle errors
	except HTTPError, e:
		print &quot;HTTP Error:&quot;,e.code , url
	except URLError, e:
		print &quot;URL Error:&quot;,e.reason , url

# Set the range of images to 1-50.It says 51 because the
# range function never gets to the endpoint.
image_range = range(1,51)

# Iterate over image range
for index in image_range:

	base_url = 'http://www.techniqal.com/'
	#create file name based on known pattern
	file_name =  str(index) + &quot;.jpg&quot;
	# Now download the image. If these were text files,
	# or other ascii types, just pass an empty string
	# for the second param ala stealStuff(file_name,'',base_url)
	stealStuff(file_name,&quot;b&quot;,base_url)</pre>
</p>
<p>That’s it. It not only reports on any errors it encountered while downloading, but think of all of the time you just saved… Really though, how important is your time to you if you’re reading this blog???</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Python File Read Write with Urllib2 on techniQal support',url: 'http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/',contentID: 'post-148',code: 'Dani8542',suggestTags: '',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2008/07/31/python-file-read-write-with-urllib2/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Ruby and Rails Float Python&#8217;s Boat</title>
		<link>http://www.techniqal.com/blog/2008/03/04/ruby-and-rails-float-pythons-boat/</link>
		<comments>http://www.techniqal.com/blog/2008/03/04/ruby-and-rails-float-pythons-boat/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 03:08:06 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/2008/03/04/ruby-and-rails-float-pythons-boat/</guid>
		<description><![CDATA[Antonio over at antoniocangiano.com has a great article about the effect the rise of Rails and Ruby has had on Python. I totally agree with him regarding the meteoric rise in popularity of Rails buoying scripting languages such as python. I believe more and more businesses are choosing, or are open enough, to implement Rails <a href='http://www.techniqal.com/blog/2008/03/04/ruby-and-rails-float-pythons-boat/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.techniqal.com/blog/wp-content/uploads/2008/03/python_winner.gif" alt="python_winner.gif" /><br />
Antonio over at <a href="http://antoniocangiano.com">antoniocangiano.com</a> has a <a href="http://antoniocangiano.com/2008/03/04/rails-is-the-best-thing-that-ever-happened-to-python/">great article</a> about the effect the rise of Rails and Ruby has had on Python.</p>
<p>I totally agree with him regarding the meteoric rise in popularity of Rails buoying scripting languages such as python. I believe more and more businesses are choosing, or are open enough, to implement Rails and Django solutions for their webapps. On top of other MVC frameworks, both Django and Rails allow for fast and sometimes cheap development (the non-cheap comes in if you have to hire an over-priced rails consultant). The visibility is definitely changing the way businesses view scripting languages and allow them to be seen as a viable alternative to Java and other enterprise adopted technologies.</p>
<p>I have had a man-crush on python for quit some time, and try to spout off about it&#8217;s benefits whenever I can.<br />
I have been so close to starting a series of blog posts surrounding Python and the ease of adoption for the non-programmer.  As soon as I have more time&#8230;</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Ruby and Rails Float Python\&#039;s Boat on techniQal support',url: 'http://www.techniqal.com/blog/2008/03/04/ruby-and-rails-float-pythons-boat/',contentID: 'post-110',code: 'Dani8542',suggestTags: 'Python,rails,ruby',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2008/03/04/ruby-and-rails-float-pythons-boat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tetris in 100 lines of Python</title>
		<link>http://www.techniqal.com/blog/2006/09/21/tetris-in-100-lines-of-python/</link>
		<comments>http://www.techniqal.com/blog/2006/09/21/tetris-in-100-lines-of-python/#comments</comments>
		<pubDate>Thu, 21 Sep 2006 16:33:47 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/2006/09/21/tetris-in-100-lines-of-python/</guid>
		<description><![CDATA[Really neat example of how to use python and pygame to make a game in less than 200 lines of code. read more&#160;&#124;&#160;digg story &#160;]]></description>
			<content:encoded><![CDATA[<p>Really neat example of how to use python and pygame to make a game in less than 200 lines of code.</p>
<p><a href="http://www.nikolajbaer.us/2006/05/stepping-it-up-notch-tetris-in-100.html">read more</a>&nbsp;|&nbsp;<a href="http://digg.com/programming/Tetris_in_100_lines_of_Python">digg story</a></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Tetris in 100 lines of Python on techniQal support',url: 'http://www.techniqal.com/blog/2006/09/21/tetris-in-100-lines-of-python/',contentID: 'post-64',code: 'Dani8542',suggestTags: '',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2006/09/21/tetris-in-100-lines-of-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Squidoo Public Beta</title>
		<link>http://www.techniqal.com/blog/2005/12/08/my-squidoo-public-beta/</link>
		<comments>http://www.techniqal.com/blog/2005/12/08/my-squidoo-public-beta/#comments</comments>
		<pubDate>Thu, 08 Dec 2005 18:19:20 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/?p=52</guid>
		<description><![CDATA[So, the word is out, and Seth Godins&#8216; latest project, Squidoo, is slightly open to the public. Those of us who were closed beta testers were given the go ahead to share our Squidoo Lenses with friends and family. For those who don&#8217;t know, Squidoo, is a site that enhances the search engine ideology. It <a href='http://www.techniqal.com/blog/2005/12/08/my-squidoo-public-beta/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://static.flickr.com/35/71525031_4de510f7a6_t.jpg" alt="squid" /><br />
So, the word is out, and <a href="http://sethgodin.typepad.com/">Seth Godins</a>&#8216; latest project, <a href="http://www.squidoo.com">Squidoo</a>, is slightly open to the public. Those of us who were closed beta testers were given the go ahead to share our Squidoo Lenses with friends and family.</p>
<p>For those who don&#8217;t know, Squidoo, is a site that enhances the search engine ideology. It does this by allowing people to publish information/links and articles(Lenses) on subjects that a person(LensMaster) may have experience/expertise in.<br />
The concept allows these self proclaimed experts to provide tightly filtered and relevant information on a topic, without all of the cruft that comes along with a normal search engine.  The whole project abounds with the hottest buzzwords of the day,ie. longtail,web 2.0, ajax,etc.</p>
<p>So I decided to do a lense about the Python programming language, and it&#8217;s use on Windows. So without any further ado, the link to my Squidoo lense.<br />
<a href="http://www.squidoo.com/python_on_windows/">http://www.squidoo.com/python_on_windows/</a></p>
<p>I am currently ranked 1,777 , &#8211;so if you believe my lense has some valuable content, go ahead and rate it.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'My Squidoo Public Beta on techniQal support',url: 'http://www.techniqal.com/blog/2005/12/08/my-squidoo-public-beta/',contentID: 'post-52',code: 'Dani8542',suggestTags: '',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2005/12/08/my-squidoo-public-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Run a Script from Email</title>
		<link>http://www.techniqal.com/blog/2005/11/14/how-to-run-a-script-from-email/</link>
		<comments>http://www.techniqal.com/blog/2005/11/14/how-to-run-a-script-from-email/#comments</comments>
		<pubDate>Tue, 15 Nov 2005 00:56:59 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/?p=48</guid>
		<description><![CDATA[Got a little idea to write this up after seeing a question over on Photo Matt. He asked about having a script that could take commands sent by email and execute them remotely, then return the results via email. So I decided to hack something up in Python, and give it a try. Read the <a href='http://www.techniqal.com/blog/2005/11/14/how-to-run-a-script-from-email/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Got a little idea to write this up after seeing a question over on <a href="http://photomatt.net/">Photo Matt</a>.  He asked about having a script that could take commands sent by email and execute them remotely, then return the results via email.<br />
So I decided to hack something up in Python, and give it a try. Read the rest of the post to see how I did it.<br />
Or you can cheat and just look at the script itself. <a href="http://www.techniqal.com/blog/sys_email.html">Click Here for the script</a>.</p>
<p><span id="more-48"></span><br />
First off, you will need access to the *nix server. Probably root access.<br />
This method uses a standard python script, and the sendmail smrsh facility.<br />
You will want to start by making sure sendmail has smrsh support included.<br />
You can tell if it does by looking at /etc/mail/sendmail.mc and looking for a line &#8211;FEATURE(`smrsh&#8217;,`/usr/sbin/smrsh&#8217;)<br />
If you get that far, you are in good shape.</p>
<p>Onto configuring smrsh:</p>
<ol>
<li>Create a new user account that will recieve the email. Ex: <em>adduser my_secret_user</em>
</li>
<li>Then edit /etc/aliases and add a line like:<br />
                my_secret_user: &#8220;|/etc/smrsh/my_script_name&#8221;
</li>
<li>Then run the <em>newaliases</em> command</li>
<li>Now, all you need to do is create the script. You will need it to be named whatever you called it when adding the line to the /etc/aliases  file, and it needs to be in the /etc/smrsh directory. The example script below is the one I wrote in python. You can copy the script, and alter it for your needs. And if any python zealots see this, I know it is not well formed, and could be written much better.</li>
</ol>
<pre>
<code>

#!/usr/local/bin/python
# Change the fromaddr and toaddr values below,
# and change path to python above

import sys,os,re,string,smtplib

#who the response comes from
fromaddr = 'secret@localhost'
#who to send the email to
toaddr = 'myemail@myhost.com'

input = sys.stdin
mail = input.readlines()

for x in mail:
     #  is string to denote start of command.
     #  change it below to suit your needs.
     if re.search('*cmd*',x):
            cmd = string.replace(x,'*cmd*','')
            cmd = string.strip(cmd)
            cmd_in,cmd_out = os.popen4(cmd)
            msg = 'Subject: Output from " + cmd + '\r\n'
            msg = msg + cmd_out.read()

#Optional-- this will send email to whoever sent the original,
# un-comment out next 7 lines --otherwise, this will
#only send emails to address configured  above

# if re.search('From:',x):
#    if re.search('@',x):
#       who = string.split(x,' ')
#       toaddr = who[2]
#       toaddr = string.replace(x,'< ','')
#       toaddr = string.replace(x,'>','')

#send email
if msg:
        server = smtplib.SMTP('localhost')
        server.sendmail(fromaddr,toaddr,msg)
        server.quit()

</code>
  </pre>
<p><strong>Caveats: This is probably not safe to do. Make sure the email address is obscure enough, so it could not be guessed.<br />
Also, this will run any command the exec&#8217;ing user has rights to. So if the script is owned by root, you can do some damage.<br />
Use caution, and don&#8217;t say I didn&#8217;t warn you.</strong></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'How to Run a Script from Email on techniQal support',url: 'http://www.techniqal.com/blog/2005/11/14/how-to-run-a-script-from-email/',contentID: 'post-48',code: 'Dani8542',suggestTags: '',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2005/11/14/how-to-run-a-script-from-email/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating a Task Bar icon in wxPython</title>
		<link>http://www.techniqal.com/blog/2005/07/20/creating-a-task-bar-icon-in-wxpython/</link>
		<comments>http://www.techniqal.com/blog/2005/07/20/creating-a-task-bar-icon-in-wxpython/#comments</comments>
		<pubDate>Thu, 21 Jul 2005 01:45:00 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://192.168.0.2:8000/blog/?p=3</guid>
		<description><![CDATA[Here is another nifty tidbit of python code that is often hard to find. If you work with Python and wxPython to build gui apps, there are a number of widgets etc., that can be hard to figure out. Adding a task bar icon for your app is one of them. This simple example shows <a href='http://www.techniqal.com/blog/2005/07/20/creating-a-task-bar-icon-in-wxpython/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/Dive-Into-Python-Mark-Pilgrim/dp/1441437134/ref=sr_1_3?ie=UTF8&amp;s=books&amp;qid=1272562697&amp;sr=1-3"><img src="/blog/wp-content/uploads/python.jpg" alt="python" class="alignleft"/></a></p>
<p>Here is another nifty tidbit of python code that is often hard to find. If you work with <a class="zem_slink" href="http://www.python.org/" title="Python (programming language)" rel="homepage">Python</a> and wxPython to build gui apps, there are a number of widgets etc., that can be hard to figure out. Adding a task bar icon for your app is one of them. This simple example shows you how to add a taskbar icon, and capture events from it.</p>
<p><span id="more-3"></span><br />
<code><br />
</code>
<pre>import wx

def OnTaskBarRight(event):
             app.ExitMainLoop()
#setup app
app= wx.PySimpleApp()

#setup icon object
icon = wx.Icon("favicon.ico", wx.BITMAP_TYPE_ICO)

#setup taskbar icon
tbicon = wx.TaskBarIcon()
tbicon.SetIcon(icon, "I am an Icon")

#add taskbar icon event
wx.EVT_TASKBAR_RIGHT_UP(tbicon, OnTaskBarRight)

app.MainLoop()
</pre>
<p>Check out the documentation for <a href="http://wxpython.org/onlinedocs.php">wxPython</a>, for more information.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/6171b242-04a2-4579-ad11-2e32b765cf0c/" title="Reblog this post [with Zemanta]"><img style="border: medium none; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=6171b242-04a2-4579-ad11-2e32b765cf0c" alt="Reblog this post [with Zemanta]"/></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Creating a Task Bar icon in wxPython on techniQal support',url: 'http://www.techniqal.com/blog/2005/07/20/creating-a-task-bar-icon-in-wxpython/',contentID: 'post-3',code: 'Dani8542',suggestTags: '',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2005/07/20/creating-a-task-bar-icon-in-wxpython/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Trolltech QT 4.0 GPL’d</title>
		<link>http://www.techniqal.com/blog/2005/06/29/trolltech-qt-40-gpld/</link>
		<comments>http://www.techniqal.com/blog/2005/06/29/trolltech-qt-40-gpld/#comments</comments>
		<pubDate>Wed, 29 Jun 2005 18:17:16 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.techniqal/blog/?p=6</guid>
		<description><![CDATA[Trolltech has finally launched a GPL version of their software for Win32. This is great news for myself, and a lot of people out there.I for one, have never been able to install QT properly on my linux box. There was always some missing or mis-referenced library, and I never could get it to work. <a href='http://www.techniqal.com/blog/2005/06/29/trolltech-qt-40-gpld/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img src='/blog/wp-content/uploads/qt4.jpg' alt='qt4' class="alignleft"/></p>
<p>Trolltech has finally launched a GPL version of their software for Win32. This is great news for myself, and a lot of people out there.I for one, have never been able to install QT properly on my linux box.<br />
There was always some missing or mis-referenced library, and I never could get it to work. I could also never seem to find the old 2.3 Win32 version that was GPL&#8217;d. Now, I can try it on my windoze box, and see if it is easier to write my Python Gui&#8217;s.</p>
<p><a href="http://www.trolltech.com/download/qt/windows.html">Click here for the win32 download mirrors!</a></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Trolltech QT 4.0 GPL’d on techniQal support',url: 'http://www.techniqal.com/blog/2005/06/29/trolltech-qt-40-gpld/',contentID: 'post-6',code: 'Dani8542',suggestTags: '',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2005/06/29/trolltech-qt-40-gpld/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Python Socket Test</title>
		<link>http://www.techniqal.com/blog/2005/06/20/simple-python-socket-test/</link>
		<comments>http://www.techniqal.com/blog/2005/06/20/simple-python-socket-test/#comments</comments>
		<pubDate>Mon, 20 Jun 2005 19:22:23 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/?p=14</guid>
		<description><![CDATA[python socket test tutorial]]></description>
			<content:encoded><![CDATA[<p><img src="http://photos13.flickr.com/14220438_42c4208c5c_m.jpg" alt='python' class="alignleft"/><br />
I have found that there is not a lot of documentation out there that shows you a simple way to instantiate a socket connection. Here is a simple code snippet, that shows you how to make a connection using the socket module. This would be useful for checking whether a host is listening on a particular port. This is not a full sockets implementation(no send, or recieve), but simply tests if a TCP socket is open.<br />
<span id="more-14"></span><br />
<code></p>
<pre>
import socket

#Simply change the host and port values
host = '127.0.0.1'
port = 80

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
 s.connect((host, port))
 s.shutdown(2)
 print "Success connecting to "
 print host + " on port: " + str(port)
except:
 print "Cannot connect to "
 print host + " on port: " + str(port)
</pre>
<p></code><br />
FYI- You can test for a UDP port by changing &#8220;socket.SOCK_STREAM&#8221; to &#8220;socket.SOCK_DGRAM&#8221; .<br />
<a href="http://python.org/doc/2.4.1/lib/module-socket.html"><br />
Check out the documentation for the socket module here</a>.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Simple Python Socket Test on techniQal support',url: 'http://www.techniqal.com/blog/2005/06/20/simple-python-socket-test/',contentID: 'post-14',code: 'Dani8542',suggestTags: '',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2005/06/20/simple-python-socket-test/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Great Python Articles/Tutorials</title>
		<link>http://www.techniqal.com/blog/2005/05/17/great-python-articlestutorials/</link>
		<comments>http://www.techniqal.com/blog/2005/05/17/great-python-articlestutorials/#comments</comments>
		<pubDate>Tue, 17 May 2005 19:12:07 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/?p=9</guid>
		<description><![CDATA[I thought I would throw some information out there that has helped me immensely in the past. Here is a link to some articles on Devshed.com that simplify and de-mystify some common problems people have when learning Python, from beginner on up. For beginners I suggest checking out the articles here and here for info <a href='http://www.techniqal.com/blog/2005/05/17/great-python-articlestutorials/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://photos13.flickr.com/14220438_42c4208c5c_t.jpg" class="alignleft"/>I thought I would throw some information out there that has helped me immensely in the past. Here is a link to some articles on <a href="http://www.devshed.com/">Devshed.com</a> that simplify and de-mystify some common problems people have when learning Python, from beginner on up. For beginners I suggest checking out the articles <a href="http://www.devshed.com/c/a/Python/File-Management-in-Python/">here</a> and <a href="http://www.devshed.com/c/a/Python/Sockets-in-Python/">here</a> for info on file handling and sockets.<br />
Also, check out the forums if you are ever in need of some guidance or help in the world of <a href="http://python.org/">Python</a> , or just about any other language/technology.</p>
<p><a href="http://www.devshed.com/c/a/Python/">&#8211;List of articles&#8211;</a></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Great Python Articles/Tutorials on techniQal support',url: 'http://www.techniqal.com/blog/2005/05/17/great-python-articlestutorials/',contentID: 'post-9',code: 'Dani8542',suggestTags: 'Python',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2005/05/17/great-python-articlestutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: Simple File Read and Write</title>
		<link>http://www.techniqal.com/blog/2005/05/17/python-simple-file-read-and-write/</link>
		<comments>http://www.techniqal.com/blog/2005/05/17/python-simple-file-read-and-write/#comments</comments>
		<pubDate>Tue, 17 May 2005 19:08:41 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.techniqal.com/blog/?p=8</guid>
		<description><![CDATA[Though there are a lot of resources out there for Python,and great books, rarely do you find a simple reference guide that helps you navigate the basics. I found that there was not a lot of reference material to help you do the simple things, if you didn&#8217;t know what to look for. This little <a href='http://www.techniqal.com/blog/2005/05/17/python-simple-file-read-and-write/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/Dive-Into-Python-Mark-Pilgrim/dp/1441437134/ref=sr_1_3?ie=UTF8&#038;s=books&#038;qid=1272562697&#038;sr=1-3"><img src="/blog/wp-content/uploads/python.jpg" alt="python" class="alignleft"/></a><br />
Though there are a lot of resources out there for<span style="font-weight: bold;"> </span><a style="font-weight: bold;" href="http://python.org/">Python</a>,and <a href="http://www.amazon.com/Programming-Python-Mark-Lutz/dp/0596009259/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1272562363&amp;sr=8-1">great books</a>, rarely do you find a simple reference guide that helps you navigate the basics. I found that there was not a lot of reference material to help you do the simple things, if you didn&#8217;t know what to look for.</p>
<p>This little guide will focus on the basics of reading and writing files in python..<br />
<span id="more-8"></span><br />
 First we are going to focus on reading from files. Open up your Python shell,<br />
or IDE.</p>
<p>To open a file/file object :</p>
<pre>open(filename,mode)</pre>
<ol>
<li><span class="comment"></span><span style="font-style: italic;"> filename can be a file or path to a file</span></li>
<li><span class="comment"></span><span style="font-style: italic;"> mode can be any of the following</span></li>
</ol>
<ol>
<li><span class="comment"></span><span style="font-style: italic;"> &#8216;r&#8217; for reading</span></li>
<li><span class="comment"></span><span style="font-style: italic;">&#8216;r+&#8217; for reading and writing</span></li>
<li><span class="comment"></span><span style="font-style: italic;">&#8216;w&#8217; for writing</span></li>
<li><span class="comment"></span><span style="font-style: italic;">&#8216;a&#8217; for appending<br />
    </span></li>
<li><span class="comment"></span><span style="font-style: italic;">both read and write modes also have a &#8216;b&#8217; option for binary reading and writing (&#8216;rb&#8217;, or &#8216;wb&#8217;)<br />
    </span></li>
</ol>
<p>  <span class="fullpost">
<pre id="line791"><span class="comment"></span><span style="color: rgb(51, 204, 0);"></span><span style="color: rgb(0, 0, 0);">Ex:</span>
myInput = open('myfile.txt','r')</pre>
<p></span></p>
<p>This command will open the file &#8220;myfile.txt&#8221; in the current<br />
directory, in &#8220;read&#8221; mode. You can access the methods of this file<br />
using the &#8216;myInput&#8217; variable. In the example, the open command will<br />
open the file indicated in the first argument(&#8216;myfile.txt&#8217;).<br />
This argument can be a file, or the path to a file. The second<br />
argument, is the file mode.</p>
<p>Once you have a file handle(<span style="color: rgb(51, 204, 0);">myInput</span>), you can work with that<br />
file, depending on the <span style="font-style: italic;">mode</span> you opened it with. We can now start<br />
reading data from our file.</p>
<p>Ex:<br />
<span style="color: rgb(51, 204, 0);">s = myFile.read()</span> <span style="font-style: italic;">Will read entire file into a string<br />
</span><span style="color: rgb(51, 204, 0);">s = myFile.read(N) </span> <span style="font-style: italic;">Will read N bytes (1 or more) from file</span><br />
<span style="color: rgb(51, 204, 0);">s = myFile.readline()</span> <span style="font-style: italic;">Will read next line into string until end of line</span><br />
<span style="color: rgb(51, 204, 0);">L = myFile.readlines()</span>  <span style="font-style: italic;">Will read entire file into a list of strings</span></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Python: Simple File Read and Write on techniQal support',url: 'http://www.techniqal.com/blog/2005/05/17/python-simple-file-read-and-write/',contentID: 'post-8',code: 'Dani8542',suggestTags: 'Python',providerName: 'techniQal support',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.techniqal.com/blog/2005/05/17/python-simple-file-read-and-write/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.techniqal.com @ 2012-02-04 01:24:25 by W3 Total Cache -->
