<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Disclaimer: I have no knowledge of PyGame. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I think your original is a lack of checking types. You are
calling BlueCar/GreenCar/Truck.collide regardless &nbsp;of the car type. If you
pass a TruckSprite to BlueCarSprite.collide it makes sense (without knowledge
of PyGame) that it would fail because it expects a BlueCarSprite not a
TruckSprite.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>You do:&nbsp;<o:p></o:p></span></p>

<p class=MsoNormal>crash = pygame.sprite.spritecollide(playerCar,
computerSprites, False)<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if crash:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for
BlueCarSprite in crash: <span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'># This loops through crash<br>
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprites26.BlueCarSprite.collide(crash, playerCar)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for
GreenCarSprite in crash: <span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'># This loops through crash again</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprites26.GreenCarSprite.collide(crash, playerCar)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for
TruckSprite in crash: <span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'># This loops through crash for the third time</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprites26.TruckSprite.collide(crash, playerCar)<o:p></o:p></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>There are two other problems with this: 1) this is sending the
entire list of collisions to each of these functions. 2) The way you are
looping seems odd to me.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I would think you want something more like the following
(UNTESTED):<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal>crash = pygame.sprite.spritecollide(playerCar,
computerSprites, False)<o:p></o:p></p>

<p class=MsoNormal>if crash:<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; for car in crash:<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if isinstance(car,
BlueCar):<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprices26.BlueCarSprite.collide(car, playerCar)<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if isinstance(car,
GreenCar):<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprices26.GreenCarSprite.collide(car, playerCar)<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if isinstance(car,
TruckCar):<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprices26.TruckCarSprite.collide(car, playerCar)<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<o:p></o:p></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>If you really want to call all 3 collide statements, then just
remove the &#8216;if isinstance(car, \w*):&#8217; line and it will call the
collide for each. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>&nbsp;&nbsp;&nbsp; <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Ramit<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><b><i><span style='font-size:9.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Ramit Prasad </span></i></b><b><span style='font-size:9.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>|<i> JPMorgan Chase
Investment Bank </i>|<i> Currencies Technology<o:p></o:p></i></span></b></p>

<p class=MsoNormal><b><i><span style='font-size:9.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>712 Main Street </span></i></b><b><span style='font-size:9.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>|<i> Houston, TX 77002<o:p></o:p></i></span></b></p>

<p class=MsoNormal><b><i><span style='font-size:9.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>work phone: 713 - 216 - 5423<o:p></o:p></span></i></b></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
tutor-bounces+ramit.prasad=jpmchase.com@python.org
[mailto:tutor-bounces+ramit.prasad=jpmchase.com@python.org] <b>On Behalf Of </b>Greg
Nielsen<br>
<b>Sent:</b> Monday, April 25, 2011 4:37 AM<br>
<b>To:</b> Steven D'Aprano<br>
<b>Cc:</b> tutor@python.org<br>
<b>Subject:</b> Re: [Tutor] Unbound Method Error<o:p></o:p></span></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<div>

<p class=MsoNormal>First and foremost, thank you Steven for your quick and well
written response. It means a lot to me that you took the time out of your day
to answer my question, and it has really helped me better understand what it
going on.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>So the full trace back for my error is as follows:<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>Traceback (most recent call last):<br>
&nbsp; File &quot;C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py&quot;, line 19, in &lt;module&gt;<br>
&nbsp;&nbsp;&nbsp; main()<br>
&nbsp; File &quot;C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py&quot;, line 16, in main<br>
&nbsp;&nbsp;&nbsp; redracerstates26.game(startLives)<br>
&nbsp; File &quot;C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracerstates26.py&quot;, line 87, in game<br>
&nbsp;&nbsp;&nbsp; redracersprites26.BlueCarSprite.collide(BlueCarSprite,
playerCar)<br>
TypeError: unbound method collide() must be called with BlueCarSprite instance
as first argument (got GreenCarSprite instance instead)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>After reading through your explanation of unbound methods
(and wrapping my head around the concept), I came up with a quick fix that lead
to a new issue in my code. Here is what I think should work:<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>crash = pygame.sprite.spritecollide(playerCar,
computerSprites, False)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if crash:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for
BlueCarSprite in crash:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprites26.BlueCarSprite.collide(crash, playerCar)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for
GreenCarSprite in crash:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprites26.GreenCarSprite.collide(crash, playerCar)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for
TruckSprite in crash:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
redracersprites26.TruckSprite.collide(crash, playerCar)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>However, the spritecollide method returns a list, which my
collide method isn't expecting. The list should only contain the name of the
sprite the player hit. In Python 3, the method would just pull the variable out
of the list and work with it, but in Python 2, it's not expecting a list,
causing an error similar to the one seen previously:<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>Traceback (most recent call last):<br>
&nbsp; File &quot;C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py&quot;, line 19, in &lt;module&gt;<br>
&nbsp;&nbsp;&nbsp; main()<br>
&nbsp; File &quot;C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracer26.py&quot;, line 16, in main<br>
&nbsp;&nbsp;&nbsp; redracerstates26.game(startLives)<br>
&nbsp; File &quot;C:\Users\Greg\Documents\NetBeansProjects\Red Racer
26\src\redracerstates26.py&quot;, line 87, in game<br>
&nbsp;&nbsp;&nbsp; redracersprites26.BlueCarSprite.collide(crash, playerCar)<br>
TypeError: unbound method collide() must be called with BlueCarSprite instance
as first argument (got list instance instead)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>So what really has to happen now (I think) is that the list
needs to be unpacked into just a simple variable containing the name of the
sprite in question. This way the method receives the name of the instance
(self) in the way it was expecting to receive it. In your opinion, should I
unpacked the list before passing the data into the method, or attempt to define
&quot;self&quot; as a list? Is the latter even possible? I would think it would
have to be because otherwise Python could pick a variable type which you don't
want or aren't expecting it to pick and need to force it to take a certain type
of input.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>And thank you for pointing out the fact I could just make a
CarSprite class and have subclasses (basically just a different sprite image)
work with the details. You just removed over 150 lines of redundant code from
my program. And once again, thank you Steven for taking the time to help me
better understand the whole unbound method concept.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>Greg<o:p></o:p></p>

</div>

</div>

</body>

</html>

<p><span STYLE="color :#000000;background-color :#FFFFFF">
This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates.

This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities.
</span></p>