Article From:https://www.cnblogs.com/lanyangsh/p/9061753.html

problem

The following code executes normally on some machines.

import json


output={}

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.

solutions

The code is modified as follows:

import json


output={}

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 *