extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.11k stars 224 forks source link

Passing filename dynamically #8 #122

Open sundaresanab opened 6 years ago

sundaresanab commented 6 years ago

Hi,

We are trying to pass the filename dynamically in 'make_clustergrammer.py', each call the text file name will be different.

fileName = sys.argv[1:]
loadFile = ''.join(fileName)
decoded_string = bytes(loadFile, "utf-8").decode("unicode_escape") # python3 
# load matrix tsv file
tempassign = decoded_string.replace('\"','')
confilename = 'txt/' + tempassign  + '.' + 'txt'
print(confilename )
net.load_file(confilename)

Error which I'm getting as follows,

FileNotFoundError: [Errno 2] No such file or directory: 'txt/.txt'

1 . assigned variable is empty

  1. I m communicating python script from nodejs.

Pls help me out, i got stuck with this more than a week.

Really, this clustergrammer is what needed exactly for our project.

We using MEAN(MongoDb, ExpressJS, Angular 4, NodeJs).

Actual prob is when i assign the argv[1:] to a variable and use that variable as parameter for 'net.load_file('filename')', it is empty.

Hard code: capture

capture1

capture 2

Thanks in advance.

san-j-vig commented 6 years ago

Are you able to print the fileconname on line 15 in your second screenshot?

sundaresanab commented 6 years ago

Yes, it is printing the value. But when i pass it as argument in next line, it is empty.

san-j-vig commented 6 years ago

Add these lines above net.load_file():

print (fileconname) sys.exit()

And post the output here.

sundaresanab commented 6 years ago

Pls find the code and result screenshots,

Note 1: sys.exit( ) terminating the script, i need to load the file and write json file further. I think in order to see the exact line you asking me to terminate the script.

Note 2: Actually before executing the python script, i m creating the txt file in "D" drive.

result code

Thanks in advance.