Hi Greg,

You must use the class definition not an instance/object of it.  If the class 
is called CarClass
from some_lib_a.sub_lib_b import CarClass
[...]
isinstance(car, CarClass)
OR
import some_lib_a
[...]
isinstance(car, some_lib_a.sub_lib_b.CarClass)


The following does NOT work:
isinstance(car, CarClass())

if you want to check multiple classes use
isinstance(car, (Class1, Class2))

Ramit



Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

From: Greg Nielsen [mailto:gollumgreg407...@gmail.com]
Sent: Monday, April 25, 2011 3:19 PM
To: Prasad, Ramit
Cc: Steven D'Aprano; tutor@python.org
Subject: Re: [Tutor] Unbound Method Error

Ramit,

     First, thank you for your input and insight into my problem, I believe 
that the code you came up with should not only be more efficient, but also 
clear up the last of my issues. I just have a quick question on the isinstance 
command you called. How exactly do I get the code to recognize it as a class I 
wrote sitting in an imported library file? I would guess that it would look 
sort of like this:

       if crash:
           for car in crash:
                if isinstance(car, redracersprites26.BlueCarSprite()):
                    redracersprites26.BlueCarSprite.collide(car, playerCar)

However, worded as it the follow error and call back happens:

Traceback (most recent call last):
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer 
26\src\redracer26.py", line 19, in <module>
    main()
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer 
26\src\redracer26.py", line 16, in main
    redracerstates26.game(startLives)
  File "C:\Users\Greg\Documents\NetBeansProjects\Red Racer 
26\src\redracerstates26.py", line 87, in game
    if isinstance(car, redracersprites26.BlueCarSprite()):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and 
types
I must be using the wrong syntax in the second argument. I think I should be 
able to find the documentation for this (extremely cool) method you showed me, 
but if you know the proper way to cite my object, could you send me what you 
think will work. This way I can have something to double check my work against 
if I don't get it right first time round. Thank you again for your time and 
assistance Ramit.

Greg


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.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to