Skip to content

Commit

Permalink
added documentation for floats
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Apr 21, 2020
1 parent 2f84533 commit a89d8c3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
15 changes: 15 additions & 0 deletions docs/src/alternatives.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Alternatives
============

argparse
--------

This is a `stdlib module <https://docs.python.org/3/library/argparse.html>`_
for building a CLI. It's powerful, but quite verbose. It's a good option
if you don't want any external dependencies in your project.

click
-----

`Click <https://github.com/pallets/click>`_ is a popular third party package
for building a CLI. It makes extensive use of decorators.
1 change: 1 addition & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ And from the command line:
docstrings.rst
cli.rst
related_projects.rst
alternatives.rst
26 changes: 21 additions & 5 deletions docs/src/supported_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Targ currently supports basic Python types:
* str
* int
* bool
* float

You must specify a type annotation for all function arguments, so Targ can
convert the input it receives from the command line into the correct type.
Expand All @@ -18,14 +19,14 @@ str
def say_hello(name: str):
print(f'hello {name}')
Ways to call it:
Example usage:

.. code-block:: bash
>>> python main.py say_hello --name=bob
>>> python main.py say_hello bob
'bob'
>>> python main.py say_hello bob
>>> python main.py say_hello --name=bob
'bob'
When your string contains spaces, use quotation marks:
Expand All @@ -43,7 +44,7 @@ int
def add(a: int, b: int):
print(a + b)
Ways to call it:
Example usage:

.. code-block:: bash
Expand All @@ -64,7 +65,7 @@ bool
else:
print("3.14")
Ways to call it:
Example usage:

.. code-block:: bash
Expand All @@ -87,3 +88,18 @@ You can use `t` as an alias for `true`, and likewise `f` as an alias for
>>> python main.py print_pi --precise=t
3.14159265
float
-----

.. code-block:: python
def compound_interest(interest_rate: float, years: int):
print(((interest_rate + 1) ** years) - 1)
Example usage:

.. code-block:: bash
>>> python main.py compound_interest 0.05 5
0.27628156250000035
13 changes: 13 additions & 0 deletions example_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,23 @@ def print_pi(precise: bool = False):
print("3.14")


def compound_interest(interest_rate: float, years: int):
"""
Work out the compound interest over the given number of years.
:param interest_rate:
The annual interest rate e.g. 0.05
:param years:
The number of years over which to compound.
"""
print(((interest_rate + 1) ** years) - 1)


if __name__ == "__main__":
cli = CLI()
cli.register(say_hello)
cli.register(echo)
cli.register(add)
cli.register(print_pi)
cli.register(compound_interest)
cli.run()

0 comments on commit a89d8c3

Please sign in to comment.