How to support both argparse and optparse?

I have a small application that runs on fairly recent Linux distributions with Python 2.7+, as well as CentOS and Scientific Linux, which have not yet made the switch to Python 2.7. optparse deprecated from Python 2.7, and frankly, I don't want to support optparse , so I developed an application with argparse . However, argparse does not exist on these older distributions. Moreover, system administrators are quite suspicious of installing backport argparse .

Now what should I do? Stick to optparse ? Create another wrapper around both libraries? To convince system administrators and users (who in most cases just can run the application) to install argparse backport?

+4
source share
2 answers

I would stick with optparse as long as it provides the functionality that you currently need (and is expected to be needed in the future).

optparse works just fine, it just won't evolve further. It is still available in Python 3, so even if one day you decide to upgrade to Python 3, it will continue to work.

+3
source

Provide a copy of argparse.py your program, since there is no need to install the module. It is enough to get argparse.py from pypi.python.org/pypi/argparse and place it in a specific place included in sys.path .

+3
source

Source: https://habr.com/ru/post/1435011/


All Articles