Closed xiaoxstz closed 4 months ago
I don't know why count
throws the errors
python Hello.py Bob count
throw errors below:
Traceback (most recent call last):
File "D:\Desktop\Hello.py", line 8, in <module>
fire.Fire(hello)
File "C:\Users\tanzi\scoop\apps\mambaforge\current\Lib\site-packages\fire\core.py", line 143, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tanzi\scoop\apps\mambaforge\current\Lib\site-packages\fire\core.py", line 477, in _Fire
component, remaining_args = _CallAndUpdateTrace(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tanzi\scoop\apps\mambaforge\current\Lib\site-packages\fire\core.py", line 693, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
TypeError: count() takes at least 1 argument (0 given)
According to the message, I tried the command below. It works.
python Hello.py Bob # output: Hello Bob!
python Hello.py Bob count "o" # output: 2
python Hello.py Bob count "h" # output: 0
python Hello.py Bob count "H" # output: 1
python Hello.py Bob count "Hello" # output: 1
The usage is clear now. count
is used to find str in the output string.
However, checking its help throws errors: python Hello.py Bob count "Hello" --help
Traceback (most recent call last):
File "D:\Desktop\Hello.py", line 8, in <module>
fire.Fire(hello)
File "C:\Users\tanzi\scoop\apps\mambaforge\current\Lib\site-packages\fire\core.py", line 143, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tanzi\scoop\apps\mambaforge\current\Lib\site-packages\fire\core.py", line 477, in _Fire
component, remaining_args = _CallAndUpdateTrace(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tanzi\scoop\apps\mambaforge\current\Lib\site-packages\fire\core.py", line 693, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
TypeError: count() takes no keyword arguments
The solution is clear now.
python Hello.py Bob count "Hello" # Output: 1
python Hello.py Bob endswith "b" # Output: False
python Hello.py Bob endswith "!" # Output: True
python Hello.py Bob find "B" # Output: 6
python Hello.py Bob index "B" # Output: 6
python Hello.py Bob find "Bob" # Output: 6
python Hello.py Bob index "Bob" # Output: 6
Put the code (copied from official document here) below to file
hello.py
I want to explore the commands provided by
fire
. I use the command to check helppython Hello.py Bob --help
Then, I see the help like below
I know the usage of some commands, such as
capitalize
,casefold
,center
.However, the other commands whose help says
S.xxx
seems not work, for example,count
,endswith
,find
, andformat