0

I'm developing Python scripts for the automated grading of assignments using CanvasAPI, an API wrapper in Python for the Canvas learning management platform. In studying the documentation, I can successfully issue curl commands in Python for a few parameters. For example, this conversion below is for uploading rubric information for a single submission:

Curl command per the Canvas API docs:

PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id

with:

rubric_assessment[criterion_id][points]

Turns into this via the CanvasAPI Python wrapper

edit(rubric_assessment={'criterion_#':{'points': 'point #'}})

However, I'm having difficulty with the syntax for adding additional parameters, which creates what appears to be nested dictionaries. For example, if I wanted to add a text comment along with grade points, the API documentation offers this:

rubric_assessment[criterion_id][comments]

For which I've attempted:

edit(rubric_assessment={'criterion_#':{'points': 'point #'}, {'criterion_#':{'comments': 'comment_text'}}})

which generates a syntax error:

SyntaxError: positional argument follows keyword argument

I've also attempted:

edit(rubric_assessment={'criterion_#':{'points': 'point #'},{'comments': 'comment_text'}})

which generates this error:

SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

What is the proper way to structure the syntax to pass both parameters? Many thanks for any insights and assistance.

  • 3
    You're trying to use dictionaries as dictionary keys, with no associated value. You want something like `{a:b, c:d}`, or `{a:{b:c, c:d}, e:{f:g}}`. But instead you have `{a:{b:c},{d:e}}`. This last case is invalid for two reasons: (1) It attempts to use `{d:e}` as a key, and (2) there is no value associated with the key. Instead, you need something like `{a:{b:c},d:{e:f}}`, or `{a:{b:c,d:e}}`. Just remember not to use dictionaries as keys (in your case, your keys are strings), and to always follow your keys with `: value`, where `value` may or may not be a dictionary. – Tom Karzes Jun 29 '21 at 13:15

1 Answers1

1

from rubric_assessment[criterion_id][comments], it looks like you need, edit(rubric_assessment={'criterion_#':{'points': 'point #','comments':'comment_text'}})

fractal397
  • 534
  • 1
  • 5
  • 11