I have zero idea as to why I'm getting this error.
views:
171answers:
6It 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)
Returntrue
ifclass
is a subclass (direct or indirect) ofclassinfo
. A class is considered a subclass of itself.classinfo
may be a tuple of class objects, in which case every entry inclassinfo
will be checked. In any other case, aTypeError
exception is raised.
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()
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.
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"
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"