Skip to content

Commit 1ce2c1f

Browse files
added real world influence sections, misc changes
1 parent e0ce795 commit 1ce2c1f

File tree

12 files changed

+14
-17
lines changed

12 files changed

+14
-17
lines changed

calculator/calc_bash_func.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@
3838
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
3939
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
4040
});
41-
</script><div id=content class=content><main><div class=sidetoc><nav class=pagetoc></nav></div><h1 id=bash-shortcuts><a class=header href=#bash-shortcuts>Bash shortcuts</a></h1><p>In this section, you'll see how to execute Python instructions from the command line and use shell shortcuts to create simple CLI applications. This book uses <code>bash</code> as the shell to showcase examples.<h2 id=python-cli-options><a class=header href=#python-cli-options>Python CLI options</a></h2><p>Passing a file to the interpreter from the command line is one of the ways to execute a Python program. You can also use <code>-c</code> option to directly pass instructions to be executed as an argument. This is suitable for small programs, like getting the result of a mathematical expression. Here's an example:<pre><code class=language-bash>$ python3.9 -c 'print(5 ** 2)'
41+
</script><div id=content class=content><main><div class=sidetoc><nav class=pagetoc></nav></div><h1 id=bash-shortcuts><a class=header href=#bash-shortcuts>Bash shortcuts</a></h1><p>In this section, you'll see how to execute Python instructions from the command line and use shell shortcuts to create simple CLI applications. This project uses <code>bash</code> as the shell to showcase examples.<h2 id=python-cli-options><a class=header href=#python-cli-options>Python CLI options</a></h2><p>Passing a file to the interpreter from the command line is one of the ways to execute a Python program. You can also use <code>-c</code> option to directly pass instructions to be executed as an argument. This is suitable for small programs, like getting the result of a mathematical expression. Here's an example:<pre><code class=language-bash>$ python3.9 -c 'print(5 ** 2)'
4242
25
43-
</code></pre><blockquote><p><img src=../images/info.svg alt=info> Use <code>python3.9 -h</code> to see all the available options. See <a href=https://docs.python.org/3/using/cmdline.html>docs.python: Command line and environment</a> for documentation.</blockquote><h2 id=python-repl><a class=header href=#python-repl>Python REPL</a></h2><p>If you call the interpreter without passing instructions to be executed, you'll get an interactive console known as REPL (stands for <strong>R</strong>ead <strong>E</strong>valuate <strong>P</strong>rint <strong>L</strong>oop). This is typically used to execute instructions for learning and debugging purposes. REPL is well suited to act as a calculator too. Since the result of an expression is automatically printed, you don't need to explicitly call <code>print()</code> function. A special variable <code>_</code> holds the result of the last executed expression. Here's some examples:<pre><code class=language-bash>$ python3.9
44-
Python 3.9.5 (default, May 4 2021, 09:12:57)
45-
[GCC 9.3.0] on linux
46-
Type "help", "copyright", "credits" or "license" for more information.
43+
</code></pre><blockquote><p><img src=../images/info.svg alt=info> Use <code>python3.9 -h</code> to see all the available options. See <a href=https://docs.python.org/3/using/cmdline.html>docs.python: Command line and environment</a> for documentation.</blockquote><h2 id=python-repl><a class=header href=#python-repl>Python REPL</a></h2><p>If you call the interpreter without passing instructions to be executed, you'll get an interactive console known as REPL (stands for <strong>R</strong>ead <strong>E</strong>valuate <strong>P</strong>rint <strong>L</strong>oop). This is typically used to execute instructions for learning and debugging purposes. REPL is well suited to act as a calculator too. Since the result of an expression is automatically printed, you don't need to explicitly call <code>print()</code> function. A special variable <code>_</code> holds the result of the last executed expression. Here's some examples:<pre><code class=language-bash>$ python3.9 -q
4744
>>> 2 * 31 - 3
4845
59
4946
>>> _ * 2

calculator/calculator.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
3939
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
4040
});
41-
</script><div id=content class=content><main><div class=sidetoc><nav class=pagetoc></nav></div><h1 id=cli-calculator><a class=header href=#cli-calculator>CLI Calculator</a></h1><p>In this project, you'll learn various ways in which you can use Python as a calculator from the command line. You'll also learn how you can customize the features for your specific needs. First, you'll see how you can directly pass Python code from the command line and create <code>bash</code> shortcuts to simplify the invocation. Second, you'll see how to use Python features to create a custom CLI application. Finally, you'll be given exercises to test your understanding and resource links for further exploration. The links to these sections are given below:<ul><li><a href=./calc_bash_func.html>Bash shortcuts</a><li><a href=./calc_py_cli.html>Python CLI application</a><li><a href=./exercises.html>Exercises</a></ul><h2 id=project-summary><a class=header href=#project-summary>Project summary</a></h2><ul><li>Execute Python instructions from the command line<li>Use shell shortcuts to simplify command line typing<li>Evaluate string content as Python code<li>Create user friendly command line interfaces<li>Allow <code>stdin</code> as source of user input</ul><p>The following modules and concepts will be utilized in this project:<ul><li><a href=https://docs.python.org/3/library/sys.html>docs.python: sys</a><li><a href=https://docs.python.org/3/library/argparse.html>docs.python: argparse</a><li><a href=https://docs.python.org/3/library/functions.html#eval>docs.python: eval</a><li><a href=https://docs.python.org/3/tutorial/modules.html>docs.python: Modules</a><li><a href=https://docs.python.org/3/tutorial/errors.html>docs.python: Exception handling</a></ul></main><nav class=nav-wrapper aria-label="Page navigation"><a rel=prev href=../preface.html class="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=../calculator/calc_bash_func.html class="mobile-nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a><div style="clear: both"></div></nav></div></div><nav class=nav-wide-wrapper aria-label="Page navigation"><a rel=prev href=../preface.html class="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=../calculator/calc_bash_func.html class="nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a></nav></div><script>
41+
</script><div id=content class=content><main><div class=sidetoc><nav class=pagetoc></nav></div><h1 id=cli-calculator><a class=header href=#cli-calculator>CLI Calculator</a></h1><p>In this project, you'll learn various ways in which you can use Python as a calculator from the command line. You'll also learn how you can customize the features for your specific needs. First, you'll see how you can directly pass Python code from the command line and create <code>bash</code> shortcuts to simplify the invocation. Second, you'll see how to use Python features to create a custom CLI application. Finally, you'll be given exercises to test your understanding and resource links for further exploration. The links to these sections are given below:<ul><li><a href=./calc_bash_func.html>Bash shortcuts</a><li><a href=./calc_py_cli.html>Python CLI application</a><li><a href=./exercises.html>Exercises</a></ul><blockquote><p><img src=../images/info.svg alt=info> <img src=../images/info.svg alt=info> If you are on Windows, you can still follow along most of this project by skipping the <code>bash</code> specific portions. The CLI tool creation using <code>argparse</code> isn't tied to a specific OS. Use <code>py</code> instead of <code>python3.9</code> for program execution. See <a href=https://docs.python.org/3/using/windows.html#from-the-command-line>docs.python: Windows command-line</a> and the rest of that page for more details.</blockquote><h2 id=project-summary><a class=header href=#project-summary>Project summary</a></h2><ul><li>Execute Python instructions from the command line<li>Use shell shortcuts to simplify command line typing<li>Evaluate string content as Python code<li>Create user friendly command line interfaces<li>Allow <code>stdin</code> as source of user input</ul><p>The following modules and concepts will be utilized in this project:<ul><li><a href=https://docs.python.org/3/library/sys.html>docs.python: sys</a><li><a href=https://docs.python.org/3/library/argparse.html>docs.python: argparse</a><li><a href=https://docs.python.org/3/library/functions.html#eval>docs.python: eval</a><li><a href=https://docs.python.org/3/tutorial/modules.html>docs.python: Modules</a><li><a href=https://docs.python.org/3/tutorial/errors.html>docs.python: Exception handling</a></ul><h2 id=real-world-influence><a class=header href=#real-world-influence>Real world influence</a></h2><p>I had two main reasons to implement this project:<ul><li>learn how to write a CLI application<li>a simple CLI calculator for personal use</ul><p>There are powerful tools like <a href=https://en.wikipedia.org/wiki/Bc_(programming_language)>bc</a> but I wanted easier syntax without fiddling with settings like <code>scale</code>. Instead of writing a shell script to customize <code>bc</code> for my use cases, I went with Python since I wanted to learn about the <code>argparse</code> module too.</main><nav class=nav-wrapper aria-label="Page navigation"><a rel=prev href=../preface.html class="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=../calculator/calc_bash_func.html class="mobile-nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a><div style="clear: both"></div></nav></div></div><nav class=nav-wide-wrapper aria-label="Page navigation"><a rel=prev href=../preface.html class="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=../calculator/calc_bash_func.html class="nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a></nav></div><script>
4242
window.playground_copyable = true;
4343
</script><script src=../elasticlunr.min.js charset=utf-8></script><script src=../mark.min.js charset=utf-8></script><script src=../searcher.js charset=utf-8></script><script src=../clipboard.min.js charset=utf-8></script><script src=../highlight.js charset=utf-8></script><script src=../book.js charset=utf-8></script><script src=../sidebar.js></script>

further_reading.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
3939
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
4040
});
41-
</script><div id=content class=content><main><div class=sidetoc><nav class=pagetoc></nav></div><h1 id=further-reading><a class=header href=#further-reading>Further Reading</a></h1><p>Here's some links from my comprehensive <a href=https://learnbyexample.github.io/py_resources/>list of Python learning resources</a>.<h2 id=projects><a class=header href=#projects>Projects</a></h2><ul><li><a href=https://github.com/tuvtran/project-based-learning#python>Project based learning</a><li><a href=https://github.com/norvig/pytudes>Pytudes by Peter Norvig</a><li>Books: <ul><li><a href=https://inventwithpython.com/bigbookpython/>The Big Book of Small Python Projects</a><li><a href=https://www.manning.com/books/tiny-python-projects>Tiny Python Projects</a><li><a href=https://nostarch.com/impracticalpythonprojects>Impractical Python Projects</a> and <a href=https://nostarch.com/real-world-python>Real world Python</a></ul><li><a href=https://www.reddit.com/r/learnpython/comments/k5k1h0/what_do_you_automate_with_python_at_home/>/r/learnpython: What do you automate with Python at home?</a><li><a href=https://rosettacode.org/wiki/Category:Python>Rosettacode</a></ul><h2 id=intermediate><a class=header href=#intermediate>Intermediate</a></h2><ul><li><a href=https://inventwithpython.com/beyond/chapter0.html>Beyond the Basic Stuff with Python</a> — Best Practices, Tools, and Techniques, OOP, Practice Projects<li>Testing and Style guides <ul><li><a href=https://calmcode.io/>Calmcode</a> — videos on testing, code style, args kwargs, data science, etc<li><a href=https://blog.thea.codes/my-python-testing-style-guide/>Python testing style guide</a><li><a href=https://realpython.com/python-testing/>Getting started with testing in Python</a><li><a href=https://mathspp.com/blog/pydonts>Pydon'ts: Write elegant Python code</a></ul><li><a href=https://runestone.academy/runestone/books/published/pythonds/index.html>Problem solving with algorithms and data structures</a></ul><h2 id=advanced><a class=header href=#advanced>Advanced</a></h2><ul><li><a href=https://www.oreilly.com/library/view/fluent-python-2nd/9781492056348/>Fluent Python</a> — takes you through Python’s core language features and libraries, and shows you how to make your code shorter, faster, and more readable at the same time<li><a href=https://nostarch.com/seriouspython>Serious Python</a> — deployment, scalability, testing, and more<li><a href=https://www.manning.com/books/practices-of-the-python-pro>Practices of the Python Pro</a> — learn to design professional-level, clean, easily maintainable software at scale, includes examples for software development best practices<li><a href=https://pragprog.com/titles/dmpython/intuitive-python/>Intuitive Python</a> — productive development for projects that last</ul></main><nav class=nav-wrapper aria-label="Page navigation"><a rel=prev href=square_tic_tac_toe/exercises.html class="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><div style="clear: both"></div></nav></div></div><nav class=nav-wide-wrapper aria-label="Page navigation"><a rel=prev href=square_tic_tac_toe/exercises.html class="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a></nav></div><script>
41+
</script><div id=content class=content><main><div class=sidetoc><nav class=pagetoc></nav></div><h1 id=further-reading><a class=header href=#further-reading>Further Reading</a></h1><p>Here's some resources to help you become a better Python programmer.<h2 id=project-planning><a class=header href=#project-planning>Project planning</a></h2><ul><li><a href=https://peterlunch.com/how-to-plan-and-build-a-programming-project/>How to Plan and Build a Programming Project</a><li><a href=https://github.com/bast/somepackage>Somepackage</a> — Show how to structure a Python project</ul><h2 id=books-on-python-projects><a class=header href=#books-on-python-projects>Books on Python projects</a></h2><ul><li><a href=https://inventwithpython.com/bigbookpython/>The Big Book of Small Python Projects</a><li><a href=https://www.manning.com/books/tiny-python-projects>Tiny Python Projects</a><li><a href=https://nostarch.com/impracticalpythonprojects>Impractical Python Projects</a> and <a href=https://nostarch.com/real-world-python>Real world Python</a></ul><h2 id=project-lists-and-tutorials><a class=header href=#project-lists-and-tutorials>Project lists and tutorials</a></h2><ul><li><a href=https://github.com/tuvtran/project-based-learning#python>Project based learning</a><li><a href=https://realpython.com/tutorials/projects/>Python Projects You Can Build</a><li><a href=https://github.com/norvig/pytudes>Pytudes by Peter Norvig</a><li><a href=https://www.reddit.com/r/learnpython/comments/k5k1h0/what_do_you_automate_with_python_at_home/>/r/learnpython: What do you automate with Python at home?</a><li><a href=https://github.com/danistefanovic/build-your-own-x>Build your own (insert technology here)</a></ul><h2 id=intermediate><a class=header href=#intermediate>Intermediate</a></h2><ul><li><a href=https://inventwithpython.com/beyond/chapter0.html>Beyond the Basic Stuff with Python</a> — Best Practices, Tools, and Techniques, OOP, Practice Projects<li>Testing and Style guides <ul><li><a href=https://calmcode.io/>Calmcode</a> — videos on testing, code style, args kwargs, data science, etc<li><a href=https://blog.thea.codes/my-python-testing-style-guide/>Python testing style guide</a><li><a href=https://realpython.com/python-testing/>Getting started with testing in Python</a><li><a href=https://mathspp.com/blog/pydonts>Pydon'ts: Write elegant Python code</a></ul><li><a href=https://runestone.academy/runestone/books/published/pythonds/index.html>Problem solving with algorithms and data structures</a></ul><h2 id=advanced><a class=header href=#advanced>Advanced</a></h2><ul><li><a href=https://www.oreilly.com/library/view/fluent-python-2nd/9781492056348/>Fluent Python</a> — takes you through Python’s core language features and libraries, and shows you how to make your code shorter, faster, and more readable at the same time<li><a href=https://nostarch.com/seriouspython>Serious Python</a> — deployment, scalability, testing, and more<li><a href=https://www.manning.com/books/practices-of-the-python-pro>Practices of the Python Pro</a> — learn to design professional-level, clean, easily maintainable software at scale, includes examples for software development best practices<li><a href=https://pragprog.com/titles/dmpython/intuitive-python/>Intuitive Python</a> — productive development for projects that last</ul><h2 id=resources-list><a class=header href=#resources-list>Resources list</a></h2><p>See my comprehensive <a href=https://learnbyexample.github.io/py_resources/>list of Python learning resources</a> for more such resources.</main><nav class=nav-wrapper aria-label="Page navigation"><a rel=prev href=square_tic_tac_toe/exercises.html class="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><div style="clear: both"></div></nav></div></div><nav class=nav-wide-wrapper aria-label="Page navigation"><a rel=prev href=square_tic_tac_toe/exercises.html class="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a></nav></div><script>
4242
window.playground_copyable = true;
4343
</script><script src=elasticlunr.min.js charset=utf-8></script><script src=mark.min.js charset=utf-8></script><script src=searcher.js charset=utf-8></script><script src=clipboard.min.js charset=utf-8></script><script src=highlight.js charset=utf-8></script><script src=book.js charset=utf-8></script><script src=sidebar.js></script>

0 commit comments

Comments
 (0)