<?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>Max Manders &#187; Python</title>
	<atom:link href="http://maxmanders.co.uk/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://maxmanders.co.uk</link>
	<description>thoughts of a web developer</description>
	<lastBuildDate>Mon, 16 Jan 2012 22:29:59 +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 Lambda Expressions</title>
		<link>http://maxmanders.co.uk/2009/11/19/python-lambda-expressions/</link>
		<comments>http://maxmanders.co.uk/2009/11/19/python-lambda-expressions/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 14:52:55 +0000</pubDate>
		<dc:creator>maxmanders</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://maxmanders.co.uk/?p=145</guid>
		<description><![CDATA[I&#8217;ve been writing a small Python/Tk application and until recently was having trouble with menu item callback functions.  I have a series of menu items, all of which do much the same thing, but within the context of an item-specific ID.  Therefore it would make sense to have a generic function that takes some parameter [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing a small Python/Tk application and until recently was having trouble with menu item callback functions.  I have a series of menu items, all of which do much the same thing, but within the context of an item-specific ID.  Therefore it would make sense to have a generic function that takes some parameter to determine what to do.<span id="more-145"></span></p>
<p>However, when adding a menu item and callback, e.g.</p>
<pre class="brush:python">
menu.add_command(label = someLabel, command = someCallback)
</pre>
<p>you must pass in the name of a function, rather than a function call.  To get around this, I used a lambda function to pass in a previously defined value to a callback:</p>
<pre class="brush:python">
id = some_value
menu.add_command(label = someLabel, command = lambda id=id: someCallback(id))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maxmanders.co.uk/2009/11/19/python-lambda-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

