You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
toFile() method from 10_05_solution.py doesn't work with extended classes like PlotScribe
Describe your environment
toDict() for PlotScribe looks like this:
{
'classname': 'PlotScribe',
'color': 'cyan',
'mark': '*',
'trail': '.',
'pos': (0, 0),
'moves': [
['_setDegrees', [135]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]]
],
'x': 0,
'domain': [0, 30]
}
Steps to Reproduce
Added these lines to end of chapter solution:
scribe3 = PlotScribe(domain=[0, 30], color='cyan')
scribe3.plotX(sine)
canvas = CanvasAxis(30, 30, scribes=[scribe, robotScribe, scribe3])
adding a custom JSON encoder class and argument cls=ScribeEncoder to json.dumps fixes it.
class ScribeEncoder(json.JSONEncoder):
def default(self, obj):
if callable(obj):
return type(obj).__name__
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
Issue Overview
toFile() method from 10_05_solution.py doesn't work with extended classes like PlotScribe
Describe your environment
toDict() for PlotScribe looks like this:{
'classname': 'PlotScribe',
'color': 'cyan',
'mark': '*',
'trail': '.',
'pos': (0, 0),
'moves': [
['_setDegrees', [135]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]],
['_plotX', [ < function sine at 0x7fc78a4aa4d0 > ]]
],
'x': 0,
'domain': [0, 30]
}
Steps to Reproduce
scribe3 = PlotScribe(domain=[0, 30], color='cyan')
scribe3.plotX(sine)
canvas = CanvasAxis(30, 30, scribes=[scribe, robotScribe, scribe3])
canvas.toFile('solution_file')
2. $ python ./exercise_files/10_05_solution.py
Expected Behavior
Example code should work with example extended scribe class
Current Behavior
TypeError: Object of type function is not JSON serializable
The text was updated successfully, but these errors were encountered: