Article From:


The following code executes normally on some machines.

import json


print json.dumps(output)

pythonWrong code:

line 277 print json.dumps(output) ^ SyntaxError: invalid syntax

This is a strange question.
After checking, the python version of the wrong machine is 3.

So, the code needs to be compatible.


The code is modified as follows:

import json


print (json.dumps(output))

printThe parameters are added to the parentheses. This enables normal execution in both python2 and python3 environments.

Leave a Reply

Your email address will not be published. Required fields are marked *