... | @@ -673,7 +673,17 @@ class TestPlayer(unittest.TestCase): |
... | @@ -673,7 +673,17 @@ class TestPlayer(unittest.TestCase): |
|
|
|
|
|
## Shapes Example
|
|
## Shapes Example
|
|
|
|
|
|
**Draft**
|
|
While this example focuses on polymorphism (e.g., abstract base classes), other
|
|
|
|
topics will be discussed, e.g.,
|
|
|
|
|
|
|
|
- Factory Pattern
|
|
|
|
- lambda functions
|
|
|
|
- `min` and `max` with lambdas as key functions
|
|
|
|
- unit tests [pyhamcrest](https://github.com/hamcrest/PyHamcrest) assertions
|
|
|
|
- Python project structure
|
|
|
|
|
|
|
|
|
|
|
|
### shape.py
|
|
|
|
|
|
```python
|
|
```python
|
|
"""
|
|
"""
|
... | @@ -752,6 +762,9 @@ class Shape(metaclass=abc.ABCMeta): |
... | @@ -752,6 +762,9 @@ class Shape(metaclass=abc.ABCMeta): |
|
return STR_FMT.format("Name", self.name)
|
|
return STR_FMT.format("Name", self.name)
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### square.py
|
|
|
|
|
|
```python
|
|
```python
|
|
import copy
|
|
import copy
|
|
|
|
|
... | @@ -817,6 +830,9 @@ class Square(Shape): |
... | @@ -817,6 +830,9 @@ class Square(Shape): |
|
+ FPT_FMT.format("Area", self.area()))
|
|
+ FPT_FMT.format("Area", self.area()))
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### shape_factory.py
|
|
|
|
|
|
```python
|
|
```python
|
|
"""
|
|
"""
|
|
This module provides factory utilities for creating shapes. This includes
|
|
This module provides factory utilities for creating shapes. This includes
|
... | @@ -918,7 +934,7 @@ def number_known(): |
... | @@ -918,7 +934,7 @@ def number_known(): |
|
return len(_KNOWN_SHAPES)
|
|
return len(_KNOWN_SHAPES)
|
|
```
|
|
```
|
|
|
|
|
|
### Shapes Driver
|
|
### run_shapes.py
|
|
|
|
|
|
```python
|
|
```python
|
|
#! /usr/bin/env python3
|
|
#! /usr/bin/env python3
|
... | @@ -1036,27 +1052,15 @@ if __name__ == "__main__": |
... | @@ -1036,27 +1052,15 @@ if __name__ == "__main__": |
|
print(err)
|
|
print(err)
|
|
```
|
|
```
|
|
|
|
|
|
### Directory Structure
|
|
|
|
|
|
|
|
```
|
|
|
|
drwxrwxr-x htmlcov
|
|
|
|
-rw-rw-r-- inputShapes.txt
|
|
|
|
-rw-rw-r-- MANIFEST
|
|
|
|
-rw-rw-r-- runTests.sh
|
|
|
|
-rw-rw-r-- setup.py
|
|
|
|
drwxrwxr-x shapes
|
|
|
|
drwxrwxr-x tests
|
|
|
|
-rw-rw-r-- tox.ini
|
|
|
|
```
|
|
|
|
|
|
|
|
# Threads & Processes
|
|
# Threads & Processes
|
|
|
|
|
|
This section will focus on a [single example](https://git-community.cs.odu.edu/tkennedy/python-workshop/-/blob/master/cs330-Python3-Toys/Example-3-parallel-coin-flip/coin_flip.py).
|
|
This section will focus on a [single
|
|
|
|
example](https://git-community.cs.odu.edu/tkennedy/python-workshop/-/blob/master/cs330-Python3-Toys/Example-3-parallel-coin-flip/coin_flip.py).
|
|
**Draft**
|
|
Topics will include:
|
|
|
|
|
|
- GIL
|
|
- Global Interpreter Lock (GIL)
|
|
- Threads vs Processes
|
|
- Threads vs Processes
|
|
- Futures
|
|
- Futures
|
|
- `ProcessPoolExecutor`
|
|
- `ProcessPoolExecutor`
|
|
- Simple timer with `datetime` |
|
- A simple timer with `datetime` |