Reputation: 177
I have a problem with my python system call. I have set up my python, path and pathext.
These commands work on my computer
run.py
python runWithParamater.py parameterExample.txt
but if I run:
runWithParamater.py parameterExample.txt
The interpreter will return "error: too few arguments".
Could anyone tell me what I'm missing?
Upvotes: 2
Views: 7519
Reputation: 177
I missed #!C:/Anaconda/python.exe(running on windows). By adding it, my arguments are counted correctly (without decreasing one if I don't use python.exe on my command)
Is there any possible solution without changing the code though? I got these scripts from a library and the default one is : "#!/usr/bin/env python". It's quite a cumbersome thing to do to add that line into all the scripts.
Upvotes: 0
Reputation: 19264
Your program runWithParameter.py
needs #!/usr/bin/env python
at the top of it. Then, in your shell, type chmod +x runWithParameter.py
. From there, you can simply type runWithParameter.py
and it will run.
Example:
foo.py
:
#!/usr/bin/env python
print 'Hello World'
And depending on your $PATH
, you can type foo.py
to run it. Else, you will have to precede it with ./
bash-3.2$ chmod +x foo.py
bash-3.2$ ./foo.py
Hello World
bash-3.2$
Or, if you are going to be running this function locally, you can define a function:
bash-3.2$ function foo.py(){
> ./foo.py
> }
bash-3.2$ foo.py
Hello World
bash-3.2$
Upvotes: 1
Reputation: 16711
Your runWithParameter.py
probably expects 3 arguments including python
.
Upvotes: 3