views:

171

answers:

6

I have zero idea as to why I'm getting this error.

+1  A: 

It means that you don't provide a class as argument for issubclass(). Both arguments have to be classes. Second argument can also be a tuple of classes.

If you show the code that throws this error, we can help further.


From the documentation:

issubclass(class, classinfo)
Return true if class is a subclass (direct or indirect) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects, in which case every entry in classinfo will be checked. In any other case, a TypeError exception is raised.

Felix Kling
@Felix:I have club class and manager class.Club class has attribute Manager where a instance of manager class should be saved.I have written functions for relationships vice-versa.I think this functions are resulting in giving issubclass error
gizgok
@gizgok: Without code it is really difficult to help.
Felix Kling
A: 

The first argument to issubclass() needs to be of type "class".

http://pyref.infogami.com/issubclass

jsumners
A: 

as people said, the 2 arguments of issubclass() should be classes, not instances of an object.

consider this sample:

>>> issubclass( 1, int )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class
>>> issubclass( type(1), int )
True    
>>> isinstance( 1, int )
True

the key is the use of the type() function to get the type of an instance for use with the issubclass() function, which, as noted in another comment, is equivalent to calling isinstance()

Adrien Plisson
Of course, classes *are* objects.
Mike Graham
well, you are right... i don't want to confuse an obvious beginner in python. i should have used 'instances of an object' (correct me if i am wrong)
Adrien Plisson
A: 

Basically this method tells you if the first parameter is a subclass of the second. So naturally, both your parameters need to be classes. It appears from your call, that you have called issubclass without any parameters, which confuses the interpreter.

Calling issubclass is like asking the interpreter: "Hey! is this class a subclass of this other class?". However, since you have not provided two classes, you have essentially asked the interpretter: "Hey! I'm not going to show you anything, but tell me if this it's a subclass". This confuses the interpreter and that's why you get this error.

inspectorG4dget
A: 
s=ZodbConnection.open_zodb()

root=s[0]

if not root.has_key("Managers"): // this line of code starts of error series

 root['Managers'] = {}

ManagerRoot=root["Managers"]

class Manager(Persistent):
  def __init__(self,clubname)
   self.clubname=Club()

def manageclubs(name):
clubname=raw_input("Current Club:") #After creating user class change for two options
currentclub=Club.findclubsbyname(clubname)
print currentclub.ClubID
manager=findmanagerbyname(name)
manager.Clubname=currentclub.ClubID
print "Working at club:%s" % manager.Clubname.Name



def findmanagerbyname(name):
 for manager in ManagerRoot.values():
         if manager.Name==name:
             managerfound=manager
             print "f"

             return managerfound
         else:
             print "!F"
gizgok
A: 
from persistent import Persistent
import transaction
from root import ZodbConnection
import Manager

class Club(Persistent):
self.Manager=Manager() #this is in init



s=ZodbConnection.open_zodb()
root=s[0]

if not root.has_key("Clubs"):
   root["Clubs"] = {}
clubs=root["Clubs"]

def addmanager(name):
  managername=raw_input("Manager:")
  manager=Manager.findmanagerbyname(managername)

  clubmanaged=findclubsbyname(name)
  clubmanaged.Manager=manager.ManagerID
  print "Club is managed by %s" % clubmanaged.Manager.Name




def findclubsbyname(name):
  for club in clubs.values():
    if club.Name==name:
        print "f"
        clubfound=club
        print clubfound.Ownername
        return clubfound
    else:
        print "!f"
gizgok