Upgrading optparse code

Originally, the argparse module had attempted to maintain compatibility with optparse. However, optparse was difficult to extend transparently, particularly with the changes required to support nargs= specifiers and better usage messages. When most everything in optparse had either been copy-pasted over or monkey-patched, it no longer seemed practical to try to maintain the backwards compatibility.

The argparse module improves on the optparse module in a number of ways including:

  • Menangani argumen posisional.

  • Mendukung subperintah.

  • Mengizinkan prefiks opsi alternatif seperti + dan /.

  • Menangani argumen gaya nol-atau-lebih dan satu-atau-lebih.

  • Menghasilkan pesan penggunaan yang lebih informatif.

  • Menyediakan antarmuka yang jauh lebih sederhana untuk type dan action kustom.

A partial upgrade path from optparse to argparse: