<?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>Microbits &#187; python</title>
	<atom:link href="http://microbits.info/index.php/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://microbits.info</link>
	<description>Random thoughts about programming, gaming, and the world.</description>
	<lastBuildDate>Mon, 31 Oct 2011 04:43:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Python for Windows applications</title>
		<link>http://microbits.info/index.php/2010/06/python-for-windows-applications</link>
		<comments>http://microbits.info/index.php/2010/06/python-for-windows-applications#comments</comments>
		<pubDate>Wed, 30 Jun 2010 23:56:25 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=632</guid>
		<description><![CDATA[From what I&#8217;ve seen of Python, I relegated it to CUI and backend type tasks, since C# and .NET offer a powerful GUI platform out of the box, and Python seemingly didn&#8217;t have anything similar. After looking into the OpenERP/OpenObject project (which looks pretty neat), I realized their complex GUI was written in Python. After [...]]]></description>
			<content:encoded><![CDATA[<p>From what I&#8217;ve seen of Python, I relegated it to CUI and backend type tasks, since C# and .NET offer a powerful GUI platform out of the box, and Python seemingly didn&#8217;t have anything similar.</p>
<p>After looking into the <a href="http://openerp.com/" target="_blank">OpenERP</a>/<a href="http://openobject.com/" target="_blank">OpenObject</a> project (which looks pretty neat), I realized their complex GUI was written in Python. After a little investigation, I figured out they were using <a href="http://www.pygtk.org/" target="_blank">PyGTK</a> (Python bindings for the GTK widget toolkit) and <a href="http://glade.gnome.org/" target="_blank">Glade</a> (a GUI builder).</p>
<p>Combining Python, PyGTK and Glade seems to lead to a workable solution for creating GUIs for Python applications. There&#8217;s a nice tutorial on how all these pieces fit together <a href="http://tadeboro.blogspot.com/2009/04/gtkdialog-tutorial-part-1.html" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2010/06/python-for-windows-applications/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Good, bad or worse?</title>
		<link>http://microbits.info/index.php/2009/10/c-good-bad-or-worse</link>
		<comments>http://microbits.info/index.php/2009/10/c-good-bad-or-worse#comments</comments>
		<pubDate>Fri, 23 Oct 2009 23:20:24 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=361</guid>
		<description><![CDATA[I&#8217;ve used many different programming languages, each with their own set of benefits and flaws. C++ was the first one I learned, and every class that I&#8217;ve taken has used it (with the exception of two language classes). Before we discuss the pros and cons of  C++, here&#8217;s a factoid: C++ is based on C, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve used many different programming languages, each with their own set of benefits and flaws. C++ was the first one I learned, and every class that I&#8217;ve taken has used it (with the exception of two language classes).</p>
<p>Before we discuss the pros and cons of  C++, here&#8217;s a factoid: C++ is based on C, which was written in 1972 (approximately <strong>37 years ago</strong>) at Bell Labs for use with the UNIX operating system.<br />
<span id="more-361"></span></p>
<p>Here are a few of the things I don&#8217;t like about C++:</p>
<ul>
<li>No garbage collection</li>
<li>Poorly implemented generics</li>
<li>Local objects (there&#8217;s a reason no other language has them)</li>
<li>Real pointers (most languages have replaced pointers with &#8220;references&#8221;)</li>
<li>A tiny standard library (most languages have huge standard libraries, with Python and .NET being some of the best)</li>
</ul>
<p>There are several libraries like Boost and QT, which provide an object model, handle garbage collection, and remove the need for pointers, making C++ more developer friendly. However, we&#8217;re talking about what comes in the box, not all the accessories that you can add after.</p>
<p>C++ is compiled directly to machine code, making execution faster than languages that compile to a byte code (like C#, Java and Python (which does compilation on the fly)) and require a runtime.</p>
<p>The real question is, does this really matter anymore? Most clients have duel or quad core processors, with clock speeds in excess of 2GHz, and servers have two to eight times the power of clients.</p>
<p>In my opinion, the answer is a definitive no. Why? Hand written assembly is faster than the machine code generated by the C++ compiler, but modern applications aren&#8217;t written in assembly. Does it matter anymore? Not really, thanks to Moore&#8217;s law.</p>
<p>Since we were able to move beyond assembly, I think we can safely shelve C++, and move on to languages like C#, Java and Python for 90% of software development.</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/10/c-good-bad-or-worse/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grid computing with Linux, Game engines</title>
		<link>http://microbits.info/index.php/2009/09/grid-computing-with-linux-game-engines</link>
		<comments>http://microbits.info/index.php/2009/09/grid-computing-with-linux-game-engines#comments</comments>
		<pubDate>Sun, 06 Sep 2009 19:12:26 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[grid computing]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=319</guid>
		<description><![CDATA[If you have several old PCs lying around, you could turn them into a grid, a single computer that uses all their resources together. I haven&#8217;t found a good use for a grid personally, but I found a nice piece software to setup a SSI (Single System Image, basically means one OS running on multiple [...]]]></description>
			<content:encoded><![CDATA[<p>If you have several old PCs lying around, you could turn them into a grid, a single computer that uses all their resources together.</p>
<p>I haven&#8217;t found a good use for a grid personally, but I found <a href="http://www.kerrighed.org" target="_blank">a nice piece software</a> to setup a SSI (Single System Image, basically means one OS running on multiple machines) grid, and <a href="https://wiki.ubuntu.com/EasyUbuntuClustering/UbuntuKerrighedClusterGuide" target="_blank">a nice tutorial</a>.</p>
<p>If I had a grid running MySQL, the 35 million row DB table I use would probably search pretty fast.</p>
<p>In other news,<a href="http://www.panda3d.org" target="_blank"> Panda3D</a> (a game engine, usable from C++ or Python) looks like it has excellent documentation, something that a lot of engines are lacking. I&#8217;m also wondering if I should buy a Mac now that Snow Leopard is out (that&#8217;s when I said I&#8217;d buy one)&#8230; I wonder if I&#8217;d really use the Mac applications&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/09/grid-computing-with-linux-game-engines/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OOP in different languages</title>
		<link>http://microbits.info/index.php/2009/08/oop-in-different-languages</link>
		<comments>http://microbits.info/index.php/2009/08/oop-in-different-languages#comments</comments>
		<pubDate>Thu, 27 Aug 2009 00:30:04 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=300</guid>
		<description><![CDATA[OOP is different in each programming language. Some languages like Python and C# don&#8217;t offer all the OOP features that you can get from C++. Python doesn&#8217;t really support traditional access modifiers, and C# doesn&#8217;t offer true multiple inheritance (you can inherit from one class and multiple interfaces). While C++ offers the most OOP features [...]]]></description>
			<content:encoded><![CDATA[<p>OOP is different in each programming language. Some languages like Python and C# don&#8217;t offer all the OOP features that you can get from C++.</p>
<p>Python doesn&#8217;t really support traditional access modifiers, and C# doesn&#8217;t offer true multiple inheritance (you can inherit from one class and multiple interfaces).</p>
<p>While C++ offers the most OOP features of the three languages, it has some disadvantages. If you compare C++ to modern languages like Python, Ruby or C#, C++ starts to show it&#8217;s age. Further more, given a small application, it&#8217;s usually much faster to write it in Python than in any C language.</p>
<p>The question ultimately becomes, are all the OOP features in C++ really needed in every day development? For small projects, most likely, no. For large projects with a team of developers, maybe.</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/08/oop-in-different-languages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python&#8217;s self</title>
		<link>http://microbits.info/index.php/2009/08/pythons-self</link>
		<comments>http://microbits.info/index.php/2009/08/pythons-self#comments</comments>
		<pubDate>Thu, 27 Aug 2009 00:00:46 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=302</guid>
		<description><![CDATA[Python methods (functions that are part of a class) have a special explicit parameter called self. Through self, methods can access class members (without a self parameter, the method is static (no access to instance variables)). In most C languages, the &#8220;self&#8221; parameter is hidden (an implicit parameter), and is usually accessible through a reserved [...]]]></description>
			<content:encoded><![CDATA[<p>Python methods (functions that are part of a class) have a special explicit parameter called self. Through self, methods can access class members (without a self parameter, the method is static (no access to instance variables)).</p>
<p>In most C languages, the &#8220;self&#8221; parameter is hidden (an implicit parameter), and is usually accessible through a reserved word (e.g this is C++ and C#).</p>
<p>Which is better? Python&#8217;s upfront approach is nice for beginners, but for experienced programmers, it creates some extra work.</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/08/pythons-self/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql-python &#8211; Compiling on Windows</title>
		<link>http://microbits.info/index.php/2009/08/mysql-python-compiling-on-windows</link>
		<comments>http://microbits.info/index.php/2009/08/mysql-python-compiling-on-windows#comments</comments>
		<pubDate>Fri, 14 Aug 2009 04:59:44 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=250</guid>
		<description><![CDATA[Compiling mysql-python shouldn&#8217;t have been too complicated, since distutils automates the compilation process, but there were two minor issues. This particular module needed the /MANIFEST linker option, and the windows setup script didn&#8217;t work properly. After fixing both of those problems, I present the compiled binaries (), and the fixed setup_windows.py (), if you want [...]]]></description>
			<content:encoded><![CDATA[<p>Compiling mysql-python shouldn&#8217;t have been too complicated, since distutils automates the compilation process, but there were two minor issues.</p>
<p>This particular module needed the /MANIFEST linker option, and the windows setup script didn&#8217;t work properly.</p>
<p>After fixing both of those problems, I present the compiled binaries (<a class="downloadlink" href="http://microbits.info/wp-content/plugins/download-monitor/download.php?id=4" title=" downloaded 191 times" >MySQL-python-1.2.3c1.win32-py2.6.exe (191)</a>), and the fixed setup_windows.py (<a class="downloadlink" href="http://microbits.info/wp-content/plugins/download-monitor/download.php?id=3" title=" downloaded 198 times" >mysql-python-setup_windows.py (198)</a>), if you want to compile mysql-python yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/08/mysql-python-compiling-on-windows/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with Python (part 6 &#8211; for newbs)</title>
		<link>http://microbits.info/index.php/2009/08/getting-started-with-python-part-6-for-newbs</link>
		<comments>http://microbits.info/index.php/2009/08/getting-started-with-python-part-6-for-newbs#comments</comments>
		<pubDate>Tue, 11 Aug 2009 03:37:34 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=244</guid>
		<description><![CDATA[Loops are another &#8220;flow control&#8221; tool, like an if statement. Loops allow you to repeat the same piece of code multiple times, which can be very useful when you are processing data. There are two types of loops in Python, the for loop, and the while loop. The for loop is one of the easiest [...]]]></description>
			<content:encoded><![CDATA[<p>Loops are another &#8220;flow control&#8221; tool, like an if statement. Loops allow you to repeat the same piece of code multiple times, which can be very useful when you are processing data.</p>
<p>There are two types of loops in Python, the for loop, and the while loop. The for loop is one of the easiest ways to process data. Let&#8217;s take a look:<br />
<span id="more-244"></span></p>
<pre class="brush: python"># Define a list
a = ['test1', 'test2', 'test3']

# In the first iteration (pass through the loop)
# the value 'test1' will be assigned to the variable temp1
#
# In the second iteration, it will be assigned the value 'test2'
for temp in a:
    print temp</pre>
<p>The syntax of a for loop is as follows:</p>
<pre class="brush: python"># Define a list
a = ['test1', 'test2', 'test3']

for tempVariableName in collectionToLoopThrough:
    print 'do stuff here with the temp variable here'</pre>
<p>The other type of loop is the while loop:</p>
<pre class="brush: python"># Define a list
a = ['test1', 'test2', 'test3']

# Loop control variable
i = 0

# Store the length of the list a
max = len(a)

while i &lt; max:
   print a[i]
   i += 1</pre>
<p>The expression that follows the word while is the loop test. If true, the loop will run, and if false, it will not. The loop test is tested when the loop is first entered, and at the beginning of each iteration.</p>
<p>Loops in Python offer a lot of other control features, which you can read about <a href="http://docs.python.org/tutorial/controlflow.html#more-control-flow-tools" target="_blank">here</a>.</p>
<p>If you&#8217;ve been following the tutorials, you should have enough knowledge to learn the other features of Python on your own. If you have questions, the best place to go is either the <a href="http://docs.python.org/index.html" target="_blank">Python documentation</a>, especially the <a href="http://docs.python.org/tutorial/index.html" target="_blank">Python tutorial</a>, or <a href="http://www.google.com/" target="_blank">Google</a> (if you wanted to write program that finds and replaces words in files in a given directory, you might search for &#8220;read file python&#8221;, &#8220;file io python&#8221;, &#8220;string replace python&#8221;).</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/08/getting-started-with-python-part-6-for-newbs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Code</title>
		<link>http://microbits.info/index.php/2009/08/python-code</link>
		<comments>http://microbits.info/index.php/2009/08/python-code#comments</comments>
		<pubDate>Thu, 06 Aug 2009 08:03:04 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=221</guid>
		<description><![CDATA[I&#8217;ll be posting my Python code here. If you have questions, leave a comment the code&#8217;s download page. I just finished a little backup script, which copies files only if they are newer than the copy in the destination folder, or if they don&#8217;t exist in the destination yet.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be posting my Python code <a href="http://microbits.info/?page_id=11&amp;category=python+code" target="_blank">here</a>. If you have questions, leave a comment the code&#8217;s download page.</p>
<p>I just finished a little backup script, which copies files only if they are newer than the copy in the destination folder, or if they don&#8217;t exist in the destination yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/08/python-code/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with Python (part 5 &#8211; for newbs)</title>
		<link>http://microbits.info/index.php/2009/08/getting-started-with-python-part-5-for-newbs</link>
		<comments>http://microbits.info/index.php/2009/08/getting-started-with-python-part-5-for-newbs#comments</comments>
		<pubDate>Wed, 05 Aug 2009 21:31:23 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=197</guid>
		<description><![CDATA[Continuing from tutorial 4, we&#8217;ll discuss object oriented programming, classes, and how OO is applied in Python. First of all, if we&#8217;re not doing object oriented programming, what kind of programming are we doing? Most likely, procedural. Procedural programming uses multiple functions to accomplish a task. Object oriented programming is the idea of packaging related [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing from tutorial 4, we&#8217;ll discuss object oriented programming, classes, and how OO is applied in Python.</p>
<p>First of all, if we&#8217;re not doing object oriented programming, what kind of programming are we doing? Most likely, procedural. Procedural programming uses multiple functions to accomplish a task. Object oriented programming is the idea of packaging related variables and functions together in a reusable container called a class. Technically, OO is about modeling real world objects.<br />
<span id="more-197"></span><br />
For example:</p>
<pre class="brush: python">class Shower:
     cold_waterrate = 0
     hot_waterrate = 0
     door_state = 0

     def UpdateWaterRates(self):
         API.SetColdRate(self.cold_waterrate)
         API.SetHotWaterRate(self.hot_waterrate)

    def UpdateDoorState(self):
         API.SetDoorState(door_state)</pre>
<p>The above code <em>defines</em> a class called Shower with data (cold_waterrate, hot_waterrate and door_state) and function members (UpdateWaterRates and UpdateDoorState).</p>
<p>Defining a class creates a blueprint. Basically, the instructions that are used to create an <em>instance</em> of the class.</p>
<p>You might be wondering what the self parameter is in the methods. self is a special word in Python that is automatically set to be the object that it was called on. Without a self parameter, we wouldn&#8217;t be able to access class data from inside our function. We&#8217;ll explore this again later.</p>
<p>In order to use our new class, we need to create an instance of the class. When an instance is created, the class definition is used to construct an object. So, what&#8217;s an object? Your monitor is an object, as is your mouse, keyboard and desk. Let&#8217;s take the mouse for example; It has blueprints or plans that are used to construct each mouse object, like the one on your desk.</p>
<p>Let&#8217;s create an instance of the Shower class:</p>
<pre class="brush: python">
shower1 = Shower()
</pre>
<p>On line 1, I call the Shower class (called the &#8220;The instantiation operation&#8221; (<a href="http://docs.python.org/tutorial/classes.html#class-objects" target="_blank">source</a>)), which gives me a new instance of the Shower class, and I store that instance in shower1.</p>
<p>shower1 now contains a Shower object. I can access it like this:</p>
<pre class="brush: python">
# Like many languages, Python uses object.memberName
# to access members of a class

# Setting class data
shower1.cold_waterrate = 15
shower1.hot_waterrate = 20
shower1.door_state = 0

# Calling class methods
shower1.UpdateDoorState()
shower1.UpdateWaterRates()
</pre>
<p>When I call shower1.UpdateDoorState, I don&#8217;t specify a value for the self parameter. It is automatically passed shower1. Technically, that&#8217;s not what really happens. The Python language converts the method call &#8220;shower1.UpdateDoorState()&#8221; to &#8220;Shower.UpdateDoorState(shower1)&#8221;.</p>
<p>Many classes have a special initial state that&#8217;s needed for them to work correctly. Python provides a special method that we can define called &#8220;__init__&#8221;.</p>
<p>Here&#8217;s what the shower class looks like with an &#8220;__init__&#8221; method:</p>
<pre class="brush: python">
class Shower:
     cold_waterrate = 0
     hot_waterrate = 0
     door_state = 0

     def __init__(self):
         self.UpdateWaterRates()
         self.UpdateDoorState()

     def UpdateWaterRates(self):
         API.SetColdRate(self.cold_waterrate)
         API.SetHotWaterRate(self.hot_waterrate)

  def UpdateDoorState(self):
         API.SetDoorState(door_state)</pre>
<p>Basically, this &#8220;__init__&#8221; method will make sure the water rates and door state are set to their defaults by calling the API methods when an instance is created.</p>
<p>Suppose we wanted to add parameters to the Shower() call? We can add them in the init method:</p>
<pre class="brush: python">
     def __init__(self, cold_water, hot_water, door):
         self.cold_waterrate = cold_water
         self.hot_waterrate = hot_water
         self.door_state = door

         self.UpdateWaterRates()
         self.UpdateDoorState()
</pre>
<p>Then, we&#8217;d create instances like this:</p>
<pre class="brush: python">
shower1 = Shower(15, 20, 0)
</pre>
<p>When you call &#8220;Shower(param1, param2, param2, etc)&#8221;, your parameters go to the init method. In the above case, init would have 15 in cold_water, 20 in hot_water and 0 in door.</p>
<h2 class="cust">Lots of things are objects</h2>
<p>In Python, lots of different things are treated as objects. Class instances, functions, collections, etc.</p>
<p>Let&#8217;s look at an example function definition:</p>
<pre class="brush: python">
def Foo():
    print "Foo."
</pre>
<p>In the function definition, we associate the name Foo with the function that we are defining. In Python, even though Foo is a function, it&#8217;s really an object, which can be very useful. Let&#8217;s say I want to have a function called when a task gets completed by another function. It&#8217;s easy to pass the function I want called to the worker function:</p>
<pre class="brush: python">
def Foo():
    print "Foo."

def DoWork(callback):
    print "Doing work..."
    callback()

DoWork(Foo)
</pre>
<p>When DoWork calls it&#8217;s parameter callback, it will be calling Foo. We can also create additional names that point to the same function:</p>
<pre class="brush: python">
def Foo():
    print "Foo."

Bar = Foo

# The below statements do the same thing
Foo()
Bar()
</pre>
<p>Most of the other things in Python that are treated as objects make sense, and I won&#8217;t cover them here.</p>
<h2 class="cust">Object copies</h2>
<p>One thing to be really careful with is copying objects. Python does NOT do this for you.</p>
<p>If you were to do:</p>
<pre class="brush: python">
class Foo:
    pass

temp1 = Foo()
temp1.something = 25

# This makes temp2 another name for the instance that
# temp1 points to
temp2 = temp1

# This will overwrite temp1.something
temp2.something = 50
</pre>
<p>If you wanted to copy the object temp1 into temp2:</p>
<pre class="brush: python">
temp2 = Foo()
temp2.something = temp1.something
</pre>
<p>The same holds true for lists (since they&#8217;re objects too):</p>
<pre class="brush: python">
temp1 = ['item1', 'item2']

# This makes temp2 another name for the list that
# temp1 points to
temp2 = temp1

temp2[0] = 'itemmagic'
# temp1[0] is now 'itemmagic'
</pre>
<h2 class="cust">Related topics</h2>
<p>Something you might be wondering about:</p>
<pre class="brush: python">
class Foo:
    pass
</pre>
<p>What was that &#8220;pass&#8221; statement? Literally, it means, do nothing. Execute will &#8220;pass&#8221; by the &#8220;pass&#8221; statement. The reason I used it was to create an empty container class, into which I could store data.</p>
<p>In the next tutorial, we&#8217;ll examine a real Python script.</p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/08/getting-started-with-python-part-5-for-newbs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Coding Style</title>
		<link>http://microbits.info/index.php/2009/08/python-coding-style</link>
		<comments>http://microbits.info/index.php/2009/08/python-coding-style#comments</comments>
		<pubDate>Tue, 04 Aug 2009 02:57:21 +0000</pubDate>
		<dc:creator>recon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://microbits.info/?p=193</guid>
		<description><![CDATA[I realized I forgot to put this in my other tutorials. First, what is coding style? It defines how code should be formatted, how to name different code elements, where white space should be in expressions, how code should be documented, etc. Now you might be wondering, why should I follow a coding style? By [...]]]></description>
			<content:encoded><![CDATA[<p>I realized I forgot to put this in my other tutorials.</p>
<p>First, what is coding style? It defines how code should be formatted, how to name different code elements, where white space should be in expressions, how code should be documented, etc.</p>
<p>Now you might be wondering, why should I follow a coding style? By following <a href="http://www.python.org/dev/peps/pep-0008/" target="_blank">PEP 8</a>, Python&#8217;s official coding style, you will make your code more readable, both for yourself, and other Python developers.</p>
<p>When code is easy to read, it makes the code easier to understand, and easier to debug.</p>
<p>If you work with other programmers, and you don&#8217;t follow a decent coding style, they will be at your door with pitch forks and torches <img src='http://microbits.info/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://microbits.info/index.php/2009/08/python-coding-style/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.967 seconds -->

