From 9801ac0379c1b4d4d2ef5d2a673d006b1559783f Mon Sep 17 00:00:00 2001 From: waldek Date: Tue, 26 Oct 2021 14:31:10 +0200 Subject: [PATCH] first abstraction added --- examples/threading_abstraction.py | 30 +++++++++ learning_python3.md | 104 ++++++++++++++++++++++++++++-- 2 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 examples/threading_abstraction.py diff --git a/examples/threading_abstraction.py b/examples/threading_abstraction.py new file mode 100644 index 0000000..acc5826 --- /dev/null +++ b/examples/threading_abstraction.py @@ -0,0 +1,30 @@ +import sys +import threading +import time +import queue + +input_queue = queue.Queue() + + +def add_input(input_queue): + while True: + input_queue.put(sys.stdin.read(1)) + +def foobar(): + global input_queue + input_thread = threading.Thread(target=add_input, args=(input_queue,)) + input_thread.daemon = True + input_thread.start() + + last_update = time.time() + while True: + if time.time()-last_update>0.5: + sys.stdout.write(".") + sys.stdout.flush() + last_update = time.time() + if not input_queue.empty(): + print("\ninput:", input_queue.get()) + + +foobar() + diff --git a/learning_python3.md b/learning_python3.md index 9018a4c..81f9044 100644 --- a/learning_python3.md +++ b/learning_python3.md @@ -73,6 +73,11 @@ TODO TODO helloworld +## How to execute + +* within pycharm +* from the command line + ## Simple printing ## String formatting @@ -89,23 +94,38 @@ TODO say hello program TODO say hello plus ask for age +* slightly insist on *blocking* nature of `input()` + ## Conditional logic +* introduction to `if`, `elif` and `else` + ## Class string methods # Coding challenge - Celsius to Fahrenheit converter # Creating your own functions +## Functions that *do* something + TODO pretty_print -## Functions that *do* something +## Variable scope ## Functions that *return* something +TODO basic math functions + +# Using the standard library + +TODO import random exercise (digital dice) +TODO import datetime exercise (will it be Sunday) + +# Coding challenge - Memento Mori calculator + # Writing your first library -TODO import pretty print +TODO import pretty print and digital dice ## What are libraries? @@ -113,8 +133,84 @@ TODO import pretty print ## What is `__name__ == "__main__"`? -# Using the standard library +## Anatomy of a program -TODO import random exercise +TODO imports, functions, execution +# While loop +TODO guess the number exercise + +# Lists + +## Creating lists + +## Picking elements + +## Slicing lists + +# For loop + +TODO say hello to my friends exercise + +# Coding challenge - Cheerleader chant + +TODO nested for loop exercise + +# Dictionaries as data containers + +TODO adapt the login generator to output a dict + +# Handling files + +## Reading from a file + +## Writing to a file + +## csv, JSON and yaml + +# Coding challenge - Login generator + +TODO write a login generator as a library with a cli as program +BONUS argparse, save to file, read from file + +# Creating our own classes + +## Class examples + +TODO simple animal or vehicle exercise + +## Class inheritance + +TODO superhero game + +## Improve the login generator + +TODO convert the login generator to a class + +# Infinite programs + +* insist on the nature of scripts we did up until now + +## Logic breakdown of a simple game + +TODO hangman exercise + +## Trivial pursuit multiple choice game + +TODO [db](https://opentdb.com/api_config.php) + +## Threading + +TODO add a countdown timer to the multiple choice game + +# GUI programming + +## wxpython helloworld + +## wxpython guess the number + +# Introduction to the `logging` library + +# Coding challenge - Login generator with GUI +