0

I'm trying to build a simple command line application using Python. At the moment, I call my application in Windows PowerShell, for instance, as:

python myprog.py --input_file "test_file.json" --init_size 10

My objective is to let anyone call the application as:

myprog --input_file test_file.json  --init_size 10

What should my approach be?

2
  • 2
    You could write a batch file (myprog.bat) that hides the Python call. Otherwise you could build an executable (PyInstaller) Commented Dec 23, 2022 at 16:23
  • 1
    For use of command-line parameters see avidpython.com/python-basics/… Commented Dec 23, 2022 at 16:25

1 Answer 1

1

You can use the setuptools library to help package your application into a wheel (installable module, like from PyPi), then add the scripts argument to specify how you want to run it from the command line:

setup(
    ...
    scripts=['bin/funniest-joke'],
    ...
)

When we install the package, setuptools will copy the script to our PATH and make it available for general use

You can find more information here about how to incorporate this functionality.

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.