Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. Python Tip #120 (of 365):

Python Tip #120 (of 365):

Scheduled Pinned Locked Moved Uncategorized
pythondailypythontip
2 Posts 1 Posters 1 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • treyhunner@mastodon.socialT This user is from outside of this forum
    treyhunner@mastodon.socialT This user is from outside of this forum
    treyhunner@mastodon.social
    wrote last edited by
    #1

    Python Tip #120 (of 365):

    Optimize for CLI user experience, not just developer experience

    By default in argparse, the names that end users see for arguments are coupled to the attribute names that you as a Python script maintainer see.

    Decouple them when needed.

    You can control the argument names that a user sees with metavar:

    This uses the attribute args.path but show users FILENAME in help text:

    parser.add_argument("path", type=Path, metavar="FILENAME")

    🧵 (1/2)

    #Python #DailyPythonTip

    treyhunner@mastodon.socialT 1 Reply Last reply
    1
    0
    • treyhunner@mastodon.socialT treyhunner@mastodon.social

      Python Tip #120 (of 365):

      Optimize for CLI user experience, not just developer experience

      By default in argparse, the names that end users see for arguments are coupled to the attribute names that you as a Python script maintainer see.

      Decouple them when needed.

      You can control the argument names that a user sees with metavar:

      This uses the attribute args.path but show users FILENAME in help text:

      parser.add_argument("path", type=Path, metavar="FILENAME")

      🧵 (1/2)

      #Python #DailyPythonTip

      treyhunner@mastodon.socialT This user is from outside of this forum
      treyhunner@mastodon.socialT This user is from outside of this forum
      treyhunner@mastodon.social
      wrote last edited by
      #2

      Also consider adding a description to describe your script and help to each argument:

      parser = argparse.ArgumentParser(
      description="Compute emoji-hash for input text/file",
      )
      parser.add_argument(
      "path",
      type=Path,
      metavar="FILENAME",
      help="Input file to emoji-hash",
      )

      Developer experience DOES matter but don't forget the users.

      You're welcome to leave these customizations to the finishing touches of your Python CLI, but don't forget them!

      🧵 (2/2)

      1 Reply Last reply
      0
      • R relay@relay.infosec.exchange shared this topic
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups