home.social

#argparse — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #argparse, aggregated by home.social.

fetched live
  1. #Python now has a wonderful colorful REPL, and in 3.14 it also made #argparse look amazing! Check my silly tool for converting PNGs to #GIF animations! Thank you @hugovk, @ambv and everyone else involved... github.com/villares/sketch-a-d

  2. #Python now has a wonderful colorful REPL, and in 3.14 it also made #argparse look amazing! Check my silly tool for converting PNGs to #GIF animations! Thank you @hugovk, @ambv and everyone else involved... github.com/villares/sketch-a-d

  3. Just released! 🚀

    🐍 Python 3.15 alpha 3!

    discuss.python.org/t/python-3-

    🔬 PEP 799: A new high-frequency statistical sampling profiler and dedicated profiling package
    💬 PEP 686: Python now uses UTF-8 as the default encoding
    🌊 PEP 782: A new PyBytesWriter C API to create a Python bytes object
    🎨 Colour code snippets in argparse help: bsky.app/profile/savannah.dev/
    ⚠️ Better error messages

    #Python #Python315 #CPython #release #PEP799 #PEP686 #PEP782 #argparse

  4. Just released! 🚀

    🐍 Python 3.15 alpha 3!

    discuss.python.org/t/python-3-

    🔬 PEP 799: A new high-frequency statistical sampling profiler and dedicated profiling package
    💬 PEP 686: Python now uses UTF-8 as the default encoding
    🌊 PEP 782: A new PyBytesWriter C API to create a Python bytes object
    🎨 Colour code snippets in argparse help: bsky.app/profile/savannah.dev/
    ⚠️ Better error messages

    #Python #Python315 #CPython #release #PEP799 #PEP686 #PEP782 #argparse

  5. 🎨 Old news: I added colour to argparse CLI help in last month's Python 3.14.

    ⭐ New news: I just added colour to ruff and ty's help so they can catch up (uv already had colour).

    #Python #CLI #argparse #ruff #ty #uv #colour

  6. 🎨 Old news: I added colour to argparse CLI help in last month's Python 3.14.

    ⭐ New news: I just added colour to ruff and ty's help so they can catch up (uv already had colour).

    #Python #CLI #argparse #ruff #ty #uv #colour

  7. So my side side project to print out help for ALL the commands and subcommands and so on for an #Argparse app. Although it will make best efforts for other commands.

    `totalhelp pipx` -- seems to work.
    `totalhelp llm` -- incredibly slow.

    also has library version for

    `my_command --totalhelp` and it shows all the help for all the commands.

    pypi.org/project/totalhelp/0.1

  8. So my side side project to print out help for ALL the commands and subcommands and so on for an #Argparse app. Although it will make best efforts for other commands.

    `totalhelp pipx` -- seems to work.
    `totalhelp llm` -- incredibly slow.

    also has library version for

    `my_command --totalhelp` and it shows all the help for all the commands.

    pypi.org/project/totalhelp/0.1

  9. Had an enjoyable afternoon building a custom #cli #parser to replace #argparse in our internal tooling. I like its ease of use. But it is a custom parser and works only for my specific use case, but for use case it does more than argparse can and is simpler to use. #comandline #python

  10. Had an enjoyable afternoon building a custom #cli #parser to replace #argparse in our internal tooling. I like its ease of use. But it is a custom parser and works only for my specific use case, but for use case it does more than argparse can and is simpler to use. #comandline #python

  11. @sumanthvepa

    argparse is maybe-okay for simple things, but I don't use it for pretty much anything anymore. Have you tried one of the other extant packages that provide higher-level, more-powerful option handling?

    I use `click` extensively for complex multiple-command CLI tools.

    #click #optparse #argparse #CLI

  12. @sumanthvepa

    argparse is maybe-okay for simple things, but I don't use it for pretty much anything anymore. Have you tried one of the other extant packages that provide higher-level, more-powerful option handling?

    I use `click` extensively for complex multiple-command CLI tools.

    #click #optparse #argparse #CLI

  13. It's probably a case of #bikesheding, but I've been really unhappy with the #python 's #argparse library for a while now. It's okay for run of the mill tools, but fails for more complex command line tools that have subcommands and complex options like --no-except to negate an option.

    This is my first cut writing a command line parser for a #cli

    github.com/sumanthvepa/experim

  14. It's probably a case of #bikesheding, but I've been really unhappy with the #python 's #argparse library for a while now. It's okay for run of the mill tools, but fails for more complex command line tools that have subcommands and complex options like --no-except to negate an option.

    This is my first cut writing a command line parser for a #cli

    github.com/sumanthvepa/experim

  15. Migrated my user-space environement over to 3.14.0b1 today.

    Nice to see the majority of the packages I use work without issue, so far.

    Plus, I get that all that pretty colored output from !

  16. Huh, there is really no way in #Python #argparse to say "print full help, not only usage when an error occurs"?

    I mean, besides
    ```
    parser = argparse.ArgumentParser()
    parser.format_usage = parser.format_help
    ```
    (or similar monstrosities)

  17. Huh, there is really no way in #Python #argparse to say "print full help, not only usage when an error occurs"?

    I mean, besides
    ```
    parser = argparse.ArgumentParser()
    parser.format_usage = parser.format_help
    ```
    (or similar monstrosities)

  18. TIL: #Python's #argparse module cannot parse arguments that start with a dash. It always expects them to be a flag and then throws an error if that flag is not defined.

    github.com/python/cpython/issu

    My use case: I have a command with subparsers/subcommands, and I'd like one of these subcommands to just take all of argv that follows its name and pass it on to someplace else.

    mycmd subcmd foo -bar --baz

    subcmd.add_argument("args", nargs="*") doesn't work.

    Guess I'll have to resort to a hack.

  19. TIL: #Python's #argparse module cannot parse arguments that start with a dash. It always expects them to be a flag and then throws an error if that flag is not defined.

    github.com/python/cpython/issu

    My use case: I have a command with subparsers/subcommands, and I'd like one of these subcommands to just take all of argv that follows its name and pass it on to someplace else.

    mycmd subcmd foo -bar --baz

    subcmd.add_argument("args", nargs="*") doesn't work.

    Guess I'll have to resort to a hack.

  20. 🎉 Please welcome @savannah as the newest member of the Python core team!

    She has recently been doing lots of excellent work on the new JIT and giving argparse some long-overdue attention.

    discuss.python.org/t/vote-to-p

    Savannah is the 9th new team member so far this year, which is the most we've had since 2012 🚀

    hugovk.github.io/python-core-d

    #Python #CPython #PythonCoreTeam #JIT #argparse

  21. 🎉 Please welcome @savannah as the newest member of the Python core team!

    She has recently been doing lots of excellent work on the new JIT and giving argparse some long-overdue attention.

    discuss.python.org/t/vote-to-p

    Savannah is the 9th new team member so far this year, which is the most we've had since 2012 🚀

    hugovk.github.io/python-core-d

    #Python #CPython #PythonCoreTeam #JIT #argparse

  22. CLI Tools mit Python bauen?
    Lerne in diesem Beitrag wie du mit Argparse Argumente direkt im Terminal für Python Tools verwenden kannst:
    py-sec.de/2024/10/26/terminal-

    #python #coding #argparse #cli #pysec

  23. @mhd I was quite fond of Amiga #CLI syntax, which many did not consider a proper #Amiga subsystem because of #BCPL, but it allowed commands to pre-declare the arguments in a uniform, documented way similar to Python’s #argparse.

    It’s actually handled by BCPL’s rdargs() function, documented in cl.cam.ac.uk/~mr10/bcplman.pdf (p68).

    1/2

  24. @mhd I was quite fond of Amiga #CLI syntax, which many did not consider a proper #Amiga subsystem because of #BCPL, but it allowed commands to pre-declare the arguments in a uniform, documented way similar to Python’s #argparse.

    It’s actually handled by BCPL’s rdargs() function, documented in cl.cam.ac.uk/~mr10/bcplman.pdf (p68).

    1/2

  25. TIL that #python #argparse can't support negative floating numbers as arguments. Like, the bug is closed RESOLVED, even though if you read through the actual resolution is WONTFIX.

    They just decided that argparse (in the stdlib!) is too complex to update and we should use a different library. So now I have to port my app and in the meantime "can't resolve ticket, bug is upstream" is not very satisfying.

    Validates #rustlang's strategy of keeping std small to avoid exactly this type of issue.

  26. TIL that #python #argparse can't support negative floating numbers as arguments. Like, the bug is closed RESOLVED, even though if you read through the actual resolution is WONTFIX.

    They just decided that argparse (in the stdlib!) is too complex to update and we should use a different library. So now I have to port my app and in the meantime "can't resolve ticket, bug is upstream" is not very satisfying.

    Validates #rustlang's strategy of keeping std small to avoid exactly this type of issue.

  27. Is there an obvious way for argparse to check if the source file and destination file are the same? ie. the user has accidentally inputted the source file twice?

    This doesn't work:

    if args.source_file == args.dest_file:
    do something

    #Python #Argparse #Noob

  28. Is there an obvious way for argparse to check if the source file and destination file are the same? ie. the user has accidentally inputted the source file twice?

    This doesn't work:

    if args.source_file == args.dest_file:
    do something

    #Python #Argparse #Noob

  29. @davetron5000 @budu @pragprog Sorry it's out of print. Some tech books have a limited lifespan, although @OReillyMedia sometimes keeps "generally useful but potentially outdated" stuff available for a long time, e.g. I think they still have the original Ruby book from Matz available, which was written for #RubyLang 1.8 or 1.9 and isn't fully applicable to Ruby 3.2.2. 🤷

    #CLI argument parsing can be challenging no matter what you use. #Fishshell #argparse has a lot of limitations cf. GNU #getopt.

  30. @davetron5000 @budu @pragprog Sorry it's out of print. Some tech books have a limited lifespan, although @OReillyMedia sometimes keeps "generally useful but potentially outdated" stuff available for a long time, e.g. I think they still have the original Ruby book from Matz available, which was written for #RubyLang 1.8 or 1.9 and isn't fully applicable to Ruby 3.2.2. 🤷

    #CLI argument parsing can be challenging no matter what you use. #Fishshell #argparse has a lot of limitations cf. GNU #getopt.

  31. Is it me? Or is #Python's #argparse library overly difficult. It seems like something I would have designed. We can do better.

  32. Is it me? Or is #Python's #argparse library overly difficult. It seems like something I would have designed. We can do better.

  33. :

    "
    This command makes it easy for fish scripts and functions to handle arguments.
    "

    Example from docs:
    ```
    function mybetterfunction
    argparse h/help s/second -- $argv
    or return

    if set -ql _flag_help
    echo "mybetterfunction [-h|--help] [-s|--second] [ARGUMENT ...]"
    return 0
    end

    if set -ql _flag_second
    echo $argv[2]
    else
    echo $argv[1]
    echo $argv[3]
    end
    end
    ```

    fishshell.com/docs/current/cmd

  34. If you’re using #Python’s #argparse module to parse CLI arguments and want to have `--foo` and `--no-foo` flags, check out `action=argparse.BooleanOptionalAction`, which automatically creates `--no-foo` for you: docs.python.org/3/library/argp

    parser.add_argument('--foo', action=argparse.BooleanOptionalAction)

    Requires 3.9 though. Simple solution for 3.8:

    parser.add_argument('--foo', action='store_true')
    parser.add_argument('--no-foo', dest='foo', action='store_false')
    parser.set_defaults(foo=True)

  35. If you’re using #Python’s #argparse module to parse CLI arguments and want to have `--foo` and `--no-foo` flags, check out `action=argparse.BooleanOptionalAction`, which automatically creates `--no-foo` for you: docs.python.org/3/library/argp

    parser.add_argument('--foo', action=argparse.BooleanOptionalAction)

    Requires 3.9 though. Simple solution for 3.8:

    parser.add_argument('--foo', action='store_true')
    parser.add_argument('--no-foo', dest='foo', action='store_false')
    parser.set_defaults(foo=True)

  36. A few years ago I didn't like #clap very much, namely compared with Python's #argparse, which I love. Yesterday I was using clap for a new project and I like version 4 with the derive system and its features much better!

    #rustlang 🦀

  37. My first attempt at using #Python's #argparse for a small #CLI tool (generate a #GIF animation). I thought about learning #click but reading the documentation it didn't "click" for me...