X Tutup
The Wayback Machine - https://web.archive.org/web/20201020072037/https://github.com/google/python-fire/issues/292
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyphen vs underscore for variable names #292

Open
ludovicschwartz opened this issue Oct 19, 2020 · 0 comments
Open

Hyphen vs underscore for variable names #292

ludovicschwartz opened this issue Oct 19, 2020 · 0 comments

Comments

@ludovicschwartz
Copy link

@ludovicschwartz ludovicschwartz commented Oct 19, 2020

One common thing is to have arguments made of multiple words, for instance name of cat that can written in 3 commons way :

  • nameofcat
  • name_of_cat
  • name-of-cat

While the first one is compatible with pretty much everything, the second one should be avoided in bash (https://stackoverflow.com/questions/1253679/should-command-line-options-in-posix-style-operating-systems-be-underscore-style) and the third one in python (https://stackoverflow.com/questions/2064329/why-does-python-disallow-usage-of-hyphens-within-function-and-variable-names).

The problem here is that by default fire will take arguments name from the python code, which means that if my python code looks like this:

script.py:

import fire
def main(name_of_cat='Steve'):
    print(f'The name of the cast is {name_of_cat}')
if __name__ == '__main__':
    fire.Fire(main)

then to call it from the command line (or from a bash script), one would do

python script.py --name_of_cat Bob

This is the way I'm using it at the moment, but this feels suboptimal. Any idea on what the best practice is here ?

PS : python script.py --name-of-cat Bob would be impossible since python can't have hyphen in variable names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.
X Tutup