You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 221f636
Browse filesBrowse the repository at this point in the historyBrowse files
This folder provides the code examples for the Real Python tutorial [How to Use Generators and yield in Python](https://realpython.com/introduction-to-python-generators/).
4
+
5
+
The scripts only use Python's standard library. They read `techcrunch.csv` from the current working directory, so run them from inside this folder:
6
+
7
+
```shell
8
+
$ python data_pipeline.py
9
+
Total series A fundraising: $4380015000
10
+
```
11
+
12
+
Each script holds the code from one section of the tutorial:
13
+
14
+
| File | Tutorial section |
15
+
| --- | --- |
16
+
|`csv_reader.py`| Example 1: Reading Large Files |
17
+
|`infinite_sequence.py`| Example 2: Generating an Infinite Sequence |
18
+
|`palindromes.py`| Example 3: Detecting Palindromes |
19
+
|`advanced_gen.py`| Using Advanced Generator Methods |
20
+
|`data_pipeline.py`| Creating Data Pipelines With Generators |
21
+
|`techcrunch.csv`| The data set for Example 1 and the data pipeline |
22
+
23
+
`infinite_sequence.py` and `palindromes.py` run forever, so press <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop them. `advanced_gen.py` takes the generator method to demonstrate as an argument:
24
+
25
+
```shell
26
+
$ python advanced_gen.py send # Runs until you press Ctrl+C
27
+
$ python advanced_gen.py throw # Stops with a ValueError
28
+
$ python advanced_gen.py close # Stops with StopIteration
0 commit comments