Skip to content

Commit c96f249

Browse files
feat: cooked_input_example - Getting, cleaning, converting, and validating command line input
1 parent 6721f01 commit c96f249

File tree

8 files changed

+110
-35
lines changed

8 files changed

+110
-35
lines changed

ebook/chapters/third_party_chapters/commandline.tex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,17 @@ \subsection{Creating A Simple Progress Bar}
119119
This code snippet is similar to the last one except the fact, that this one uses the \lstinline{tqdm} package.
120120

121121
\lstinputlisting[caption=simple\_progressbar.py]{../third_party/simple_progressbar.py}
122+
123+
124+
\subsection{Cooked Input}
125+
126+
\glqq \lstinline{cooked_input} is a Python package for getting, cleaning, converting, and validating command line input.
127+
If you think of input (raw\_input in legacy Python) as raw input, then this is cooked input.\grqq
128+
129+
\lstinputlisting[caption=cooked\_input\_example.py]{../third_party/cooked_input_example.py}
130+
131+
\begin{lstlisting}[caption=Output of cooked\_input\_example.py]
132+
$ python cooked_input_example.py
133+
What is your name?: FlOriAn dAhliTz
134+
Florian Dahlitz
135+
\end{lstlisting}

ebook/python-snippets.epub

359 Bytes
Binary file not shown.

ebook/python-snippets.mobi

528 Bytes
Binary file not shown.

ebook/python-snippets.pdf

1.82 KB
Binary file not shown.

third_party/Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pytest = "*"
3939
requests = "*"
4040
xlrd = "*"
4141
pysnooper = "*"
42+
cooked-input = "*"
4243

4344
[dev-packages]
4445

third_party/Pipfile.lock

Lines changed: 87 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

third_party/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ A collection of useful snippets using third party packages.
1212
| cli_help_strings | Beautiful rendered cli help strings |
1313
| clint_cli_tool | Tool helping you to create awesome CLIs |
1414
| colored_python | Print colored text to stdout using termcolor |
15+
| cooked_input_example | Getting, cleaning, converting, and validating command line input |
1516
| count_python_bytes | Get the bytes size of all Python files in a certain directory and it's subdirectories |
1617
| display_tables | Using prettytable to display tables well-formatted in the console |
1718
| fancy_cli_header | Turns strings into ASCII text with arts fonts (fancy CLI header) |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import cooked_input as ci
2+
3+
4+
cap_cleaner = ci.CapitalizationCleaner(style=ci.ALL_WORDS_CAP_STYLE)
5+
name = ci.get_string(prompt="What is your name?", cleaners=[cap_cleaner])
6+
7+
print(name)

0 commit comments

Comments
 (0)