Thursday, 4 May 2017

Get the wrong path when execute python code by Nodejs

I am using python-shell to call a python script from my nodejs server. The python script will open a file named myfile.txt and read its content: path = os.path.abspath("myfile.txt") f = open(path, 'r')

It runs normally when I execute the python code from Python command line but when I try to call it from Nodejs, turns out that the path became "path-to-nodejs-server/bin/myfile.txt" and I catch an error "No such file/ directory .."

How can I fix it?



via Quang Hoàng

No comments:

Post a Comment