Reputation: 424
I am using a notebook (in Google Colab) in python 3 and really need to execute some python2 code with some data that is generated in my notebook !
So what I did was
data.txt
)myScript.py
) with a main()
function that parses the file from sys.argv[1]
into data and than calls my python2 functions and do all the stuff then it ends with return results
(which is a dictionary)!python2 myScript.py ./data.txt
(They are of course all in the same directory)
The command runs with no errors but no output ! How do I catch the results
that are returned in a variable that I could use later ?
Not important but could be helpful :
Is there a better way to actually achieve what I am willing to achieve ?
Upvotes: 0
Views: 1053
Reputation: 424
Thanks to @Manuel's comment on the question, I figured out this solution and it worked :
myScript.py
, I changed return results
by sys.stdout.write(json.dumps(results))
results = !python2 test_langdetect.py ./tmp_comments.txt
myVar = json.loads(results[0])
Of course you need to import json
Upvotes: 1