0

I have created a directory 'prince' which consists of a subdirectory 'src' containing 'main.py' file in it. This main.py uses Click command for input from user using command line. So currently I have to set current working directory to 'prince' in terminal and then execute my module using the command

'$ python -m src.main run --s 10 20 30'

where 'run', '--s' are my click command inputs.

Is there an easy way to wrap 'python -m src.main' to something short to execute my module along with inputs using click command ? Or any better way to execute my module along with inputs from user ?

1
  • You can use a simple shell script with the 'python -m src.main' and pass the params to the script. Commented Jan 19, 2020 at 12:08

1 Answer 1

1

I hope this will answer your question.

In your src/main.py file you could add a #!/usr/bin/env python3 shebang which means that your program is run by python by default.

And you should give it execute permissions via

chmod +x src/main.py

That means you can now run

src/main run --s 10 20 30

Instead of

$ python -m src.main run --s 10 20 30

Antother way to achieve this would be:

Create a file in the "prince" directory named "start" with Content:

python3 -m src.main "$@"

Give it executable permissions:

chmod +x start

Now you can run:

./start run --s 10 20 30
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.