1

I have python code that takes 3 command line arguments. I am on linux, and I can't figure out how to execute the file. I have compiled with python -m py_compile MyFile.py and this puts a MyFile.pyc file on my desktop, but there doesn't seem to be anything I can execute. I have tried ./MyFile.pyc arg1 arg2 arg3, but the command line says permission denied. I then tried python MyFile.py arg1 arg2 arg3, and the command line accepts this but doesn't print anything, even though the first line of Main is a print? Am I somehow not printing correctly? I really just need to be able to execute this 1 file and give it arguments.

1 Answer 1

0

Invoking the python command with the script as the first argument, followed by your script arguments should work, e.g. python MyScript.py _args_.

As an alternative, you could add a shebang at the top of the file, and make it executable with chmod +x <script>, then you could run it with ./MyScript.py _args_.

Take as a reference the following script, which should print the arguments received:

import sys

for n, arg in enumerate(sys.argv):
    print "Arg %d: %s" % (n, arg)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.