Reputation: 414
seed and n are itegers. in the output i have TypeError: <__main__._rundckdo.<locals>.createDie.<locals>.Die object at .0x2b1a1e567630> is not JSON serializable
.How can i fix this without using json library? what i am doing wrong?
def createDie(seed, n):
class Die(object):
def __init__(self,*args):
self.seed = args[0]
self.n = args[1]
def __bool__(self):
return True if self.seed>self.n else False
class Game(object):
die = Die(seed, n)
return Game.die
Upvotes: 0
Views: 82
Reputation: 7880
As per your comment, you expect createDie()
to return a boolean value. As it is, it's returning an instance of the Die
class. This is causing the TypeError
since the caller doesn't know how to serialize it.
You'll need to explicitly get the boolean value:
return bool(Game.die)
Upvotes: 1