fosstodon.org is one of the many independent Mastodon servers you can use to participate in the fediverse.
Fosstodon is an invite only Mastodon instance that is open to those who are interested in technology; particularly free & open source software. If you wish to join, contact us for an invite.

Administered by:

Server stats:

8.8K
active users

#argparse

0 posts0 participants0 posts today
Mathias Panzenböck<p>Updated my smart help text formatter for <a href="https://chaos.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> <a href="https://chaos.social/tags/gist" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>gist</span></a>: <a href="https://gist.github.com/panzi/b4a51b3968f67b9ff4c99459fb9c5b3d" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">gist.github.com/panzi/b4a51b39</span><span class="invisible">68f67b9ff4c99459fb9c5b3d</span></a> <a href="https://chaos.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a></p>
sumanthvepa<p>Had an enjoyable afternoon building a custom <a href="https://mastodon.social/tags/cli" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>cli</span></a> <a href="https://mastodon.social/tags/parser" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>parser</span></a> to replace <a href="https://mastodon.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> 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. <a href="https://mastodon.social/tags/comandline" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>comandline</span></a> <a href="https://mastodon.social/tags/python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>python</span></a></p>
C.<p><span class="h-card" translate="no"><a href="https://mastodon.social/@sumanthvepa" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>sumanthvepa</span></a></span> </p><p>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?</p><p>I use `click` extensively for complex multiple-command CLI tools.</p><p><a href="https://mindly.social/tags/click" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>click</span></a> <a href="https://mindly.social/tags/optparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>optparse</span></a> <a href="https://mindly.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> <a href="https://mindly.social/tags/CLI" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>CLI</span></a></p>
sumanthvepa<p>It's probably a case of <a href="https://mastodon.social/tags/bikesheding" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>bikesheding</span></a>, but I've been really unhappy with the <a href="https://mastodon.social/tags/python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>python</span></a> 's <a href="https://mastodon.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> 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. </p><p>This is my first cut writing a command line parser for a <a href="https://mastodon.social/tags/cli" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>cli</span></a> </p><p><a href="https://github.com/sumanthvepa/experiments/tree/develop/python/parse-dralithus-cmdline" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/sumanthvepa/experim</span><span class="invisible">ents/tree/develop/python/parse-dralithus-cmdline</span></a></p>
Kevin Bowen (has moved) :xfce:<p>Migrated my user-space environement over to <a href="https://fosstodon.org/tags/Python" class="mention hashtag" rel="tag">#<span>Python</span></a> 3.14.0b1 today.</p><p>Nice to see the majority of the packages I use work without issue, so far.</p><p>Plus, I get that all that pretty colored output from <a href="https://fosstodon.org/tags/argparse" class="mention hashtag" rel="tag">#<span>argparse</span></a>! </p><p><a href="https://fosstodon.org/tags/EyeCandy" class="mention hashtag" rel="tag">#<span>EyeCandy</span></a> <a href="https://fosstodon.org/tags/Terminal" class="mention hashtag" rel="tag">#<span>Terminal</span></a> <a href="https://fosstodon.org/tags/CLI" class="mention hashtag" rel="tag">#<span>CLI</span></a></p>
zhenech<p>Huh, there is really no way in <a href="https://chaos.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a> <a href="https://chaos.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> to say "print full help, not only usage when an error occurs"?</p><p>I mean, besides<br>```<br>parser = argparse.ArgumentParser()<br>parser.format_usage = parser.format_help<br>```<br>(or similar monstrosities)</p>
db_scheehan<p>How to create flask web app with python</p><p><a href="https://mastodon.social/tags/python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>python</span></a> <a href="https://mastodon.social/tags/flask" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>flask</span></a> <span class="h-card" translate="no"><a href="https://mastodon.social/@python_discussions" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>python_discussions</span></a></span> @htmlallthethings <a href="https://mastodon.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> </p><p><a href="https://github.com/scheehan/gen_flask_web_app_with_script" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/scheehan/gen_flask_</span><span class="invisible">web_app_with_script</span></a></p><p><a href="https://youtu.be/IkWWsGQ8eME" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">youtu.be/IkWWsGQ8eME</span><span class="invisible"></span></a></p><p><a href="https://discu.eu/?q=https%3A%2F%2Fgithub.com%2Fscheehan%2Fgen_flask_web_app_with_script.git" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">discu.eu/?q=https%3A%2F%2Fgith</span><span class="invisible">ub.com%2Fscheehan%2Fgen_flask_web_app_with_script.git</span></a></p>
scy<p>TIL: <a href="https://chaos.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a>'s <a href="https://chaos.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> 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.</p><p><a href="https://github.com/python/cpython/issues/61252" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/python/cpython/issu</span><span class="invisible">es/61252</span></a></p><p>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.</p><p>mycmd subcmd foo -bar --baz</p><p>subcmd.add_argument("args", nargs="*") doesn't work.</p><p>Guess I'll have to resort to a hack.</p>
Hugo van Kemenade<p>🎉 Please welcome <span class="h-card" translate="no"><a href="https://fosstodon.org/@savannah" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>savannah</span></a></span> as the newest member of the Python core team!</p><p>She has recently been doing lots of excellent work on the new JIT and giving argparse some long-overdue attention.</p><p><a href="https://discuss.python.org/t/vote-to-promote-savannah-ostrowski/70302" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">discuss.python.org/t/vote-to-p</span><span class="invisible">romote-savannah-ostrowski/70302</span></a></p><p>Savannah is the 9th new team member so far this year, which is the most we've had since 2012 🚀</p><p><a href="https://hugovk.github.io/python-core-devs/by-year.html" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">hugovk.github.io/python-core-d</span><span class="invisible">evs/by-year.html</span></a></p><p><a href="https://mastodon.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a> <a href="https://mastodon.social/tags/CPython" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>CPython</span></a> <a href="https://mastodon.social/tags/PythonCoreTeam" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>PythonCoreTeam</span></a> <a href="https://mastodon.social/tags/JIT" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JIT</span></a> <a href="https://mastodon.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a></p>
Anubhav<p><a href="https://hachyderm.io/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a> <a href="https://hachyderm.io/tags/click" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>click</span></a><br>Documentation examples using functions (decorators) but reference uses classes (where the actual details are) is a terrible mismatch; causes high load to reconcile the two.</p><p>So far experience had been "meh" due to the documentation; could have just as well kept using <a href="https://hachyderm.io/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a>🤷‍♂️</p><p>As click package did not provide anything better in this case, I will convert the code to use argparse instead.</p><p>Converted the next day.</p>
k-kaufhold<p>CLI Tools mit Python bauen?<br>Lerne in diesem Beitrag wie du mit Argparse Argumente direkt im Terminal für Python Tools verwenden kannst:<br><a href="https://www.py-sec.de/2024/10/26/terminal-tools-mit-argparse-in-python-erstellen/" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://www.</span><span class="ellipsis">py-sec.de/2024/10/26/terminal-</span><span class="invisible">tools-mit-argparse-in-python-erstellen/</span></a></p><p><a href="https://mastodon.social/tags/python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>python</span></a> <a href="https://mastodon.social/tags/coding" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>coding</span></a> <a href="https://mastodon.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> <a href="https://mastodon.social/tags/cli" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>cli</span></a> <a href="https://mastodon.social/tags/pysec" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>pysec</span></a></p>
Sarfraaz Ahmed<p>🎖 Atomic Habits for Software Professionals<br>Using Streamlit for your data visualisation <br>Python Data Analytics Study Guide<br>Using argparse in Python</p><p>Read more in the latest edition of MyVoD at: <a href="http://eepurl.com/iZb4lU" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">http://</span><span class="">eepurl.com/iZb4lU</span><span class="invisible"></span></a><br>Subscribe for more at: <a href="https://bit.ly/MyVoyageOf_Discovery" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">bit.ly/MyVoyageOf_Discovery</span><span class="invisible"></span></a></p><p><a href="https://mastodon.social/tags/python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>python</span></a> <a href="https://mastodon.social/tags/Streamlit" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Streamlit</span></a> <a href="https://mastodon.social/tags/visualisation" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>visualisation</span></a> <a href="https://mastodon.social/tags/MIT" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>MIT</span></a> <a href="https://mastodon.social/tags/data" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>data</span></a> <a href="https://mastodon.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> <a href="https://mastodon.social/tags/Atomic_Habit" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Atomic_Habit</span></a> <a href="https://mastodon.social/tags/software" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>software</span></a> <a href="https://mastodon.social/tags/IT" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>IT</span></a></p>
chexum<p><span class="h-card" translate="no"><a href="https://tilde.zone/@mhd" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>mhd</span></a></span> I was quite fond of Amiga <a href="https://hachyderm.io/tags/CLI" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>CLI</span></a> syntax, which many did not consider a proper <a href="https://hachyderm.io/tags/Amiga" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Amiga</span></a> subsystem because of <a href="https://hachyderm.io/tags/BCPL" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>BCPL</span></a>, but it allowed commands to pre-declare the arguments in a uniform, documented way similar to Python’s <a href="https://hachyderm.io/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a>. </p><p>It’s actually handled by BCPL’s rdargs() function, documented in <a href="https://www.cl.cam.ac.uk/~mr10/bcplman.pdf" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://www.</span><span class="">cl.cam.ac.uk/~mr10/bcplman.pdf</span><span class="invisible"></span></a> (p68).</p><p>1/2</p>
aburka 🫣<p>TIL that <a href="https://hachyderm.io/tags/python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>python</span></a> <a href="https://hachyderm.io/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> 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.</p><p>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.</p><p>Validates <a href="https://hachyderm.io/tags/rustlang" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>rustlang</span></a>'s strategy of keeping std small to avoid exactly this type of issue.</p>
skribe 🇺🇦 :verified_mustard:<p>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?<br> <br>This doesn't work:</p><p>if args.source_file == args.dest_file:<br> do something</p><p><a href="https://aus.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a> <a href="https://aus.social/tags/Argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Argparse</span></a> <a href="https://aus.social/tags/Noob" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Noob</span></a></p>
Todd A. Jacobs | Rubyist<p><span class="h-card" translate="no"><a href="https://ruby.social/@davetron5000" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>davetron5000</span></a></span> <span class="h-card" translate="no"><a href="https://ruby.social/@budu" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>budu</span></a></span> <span class="h-card" translate="no"><a href="https://techhub.social/@pragprog" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>pragprog</span></a></span> Sorry it's out of print. Some tech books have a limited lifespan, although <span class="h-card" translate="no"><a href="https://techhub.social/@OReillyMedia" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>OReillyMedia</span></a></span> 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 <a href="https://ruby.social/tags/RubyLang" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>RubyLang</span></a> 1.8 or 1.9 and isn't fully applicable to Ruby 3.2.2. 🤷</p><p><a href="https://ruby.social/tags/CLI" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>CLI</span></a> argument parsing can be challenging no matter what you use. <a href="https://ruby.social/tags/Fishshell" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Fishshell</span></a> <a href="https://ruby.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> has a lot of limitations cf. GNU <a href="https://ruby.social/tags/getopt" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>getopt</span></a>.</p>
Sven<p>Is it me? Or is <a href="https://mastodon.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a>'s <a href="https://mastodon.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> library overly difficult. It seems like something I would have designed. We can do better.</p>
yugaego 🌍<p><a href="https://fosstodon.org/tags/TIL" class="mention hashtag" rel="tag">#<span>TIL</span></a> : <a href="https://fosstodon.org/tags/fishshell" class="mention hashtag" rel="tag">#<span>fishshell</span></a> <a href="https://fosstodon.org/tags/argparse" class="mention hashtag" rel="tag">#<span>argparse</span></a></p><p>&quot;<br />This command makes it easy for fish scripts and functions to handle arguments.<br />&quot;</p><p>Example from docs:<br />```<br />function mybetterfunction<br /> argparse h/help s/second -- $argv<br /> or return</p><p> if set -ql _flag_help<br /> echo &quot;mybetterfunction [-h|--help] [-s|--second] [ARGUMENT ...]&quot;<br /> return 0<br /> end</p><p> if set -ql _flag_second<br /> echo $argv[2]<br /> else<br /> echo $argv[1]<br /> echo $argv[3]<br /> end<br />end<br />```</p><p><a href="https://fishshell.com/docs/current/cmds/argparse.html" target="_blank" rel="nofollow noopener" translate="no"><span class="invisible">https://</span><span class="ellipsis">fishshell.com/docs/current/cmd</span><span class="invisible">s/argparse.html</span></a></p>
scy<p>If you’re using <a href="https://chaos.social/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a>’s <a href="https://chaos.social/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a> 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: <a href="https://docs.python.org/3/library/argparse.html#action" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">docs.python.org/3/library/argp</span><span class="invisible">arse.html#action</span></a></p><p>parser.add_argument('--foo', action=argparse.BooleanOptionalAction)</p><p>Requires 3.9 though. Simple solution for 3.8:</p><p>parser.add_argument('--foo', action='store_true')<br>parser.add_argument('--no-foo', dest='foo', action='store_false')<br>parser.set_defaults(foo=True)</p>
Anubhav<p><span class="h-card"><a href="https://mastodon.social/@funkylab" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>funkylab</span></a></span> That is hilarious, more so with "WontFix" <a href="https://github.com/python/cpython/issues/96994" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/python/cpython/issu</span><span class="invisible">es/96994</span></a><br><a href="https://hachyderm.io/tags/Python" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Python</span></a> <a href="https://hachyderm.io/tags/argparse" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>argparse</span></a></p>