Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python version conflict with json.dumps

I am a newb to python. I am running a script I got on the web :

python file.py

I get this :

File "file.py", line 293
    print json.dumps(evaluate(), indent=4)
             ^
SyntaxError: invalid syntax

I read it is related to python version, that should be some 2.7. So I downloaded pyenv. And I set the right version in the directory that contains file.py : pyenv local 2.7.10. But I still get the same error.

(For information, I am trying to install blockchain tool : ethereum)

like image 514
epsilones Avatar asked Dec 03 '15 00:12

epsilones


People also ask

What is the difference between JSON dump and JSON dumps?

json. dump() method used to write Python serialized object as JSON formatted data into a file. json. dumps() method is used to encodes any Python object into JSON formatted String.

What does JSON dumps do in Python?

The json. dumps() method allows us to convert a python object into an equivalent JSON object. Or in other words to send the data from python to json.

What is the difference between JSON dumps and JSON loads in Python?

loads() takes in a string and returns a json object. json. dumps() takes in a json object and returns a string.

Does JSON dump append or overwrite?

it would append the new data. the problem with this approach is that it literally appends the data so that it ends up like {... original data...}{


1 Answers

Python 3.x changed print statement to be print functions

Python 2.x:

print "Hello World" 

Python 3.x

print("Hello World")

So because you are running on python 3.x you will need to update your code to use the 3.x print style (e.g., print function calls).

print( json.dumps(evaluate(), indent=4) )
like image 67
Brian Cain Avatar answered Oct 16 '22 14:10

Brian Cain