GitHub

Original file line numberDiff line numberDiff line change

@@ -143,6 +143,8 @@ All iterators can be placed to the right of the `in` keyword in `for` loop state

143143

In fact this is how the `for` loop works: If we write

144144
145145

```{code-block} python3

146+

:class: no-execute

147+
146148

for x in iterator:

147149

<code block>

148150

```

@@ -156,6 +158,8 @@ then the interpreter

156158

So now you know how this magical looking syntax works

157159
158160

```{code-block} python3

161+

:class: no-execute

162+
159163

f = open('somefile.txt', 'r')

160164

for line in f:

161165

# do something

@@ -527,6 +531,8 @@ We are now working in the module `__main__`, and hence the namespace for `__main

527531

Next, we import a module called `amodule`

528532
529533

```{code-block} python3

534+

:class: no-execute

535+
530536

import amodule

531537

```

532538

@@ -1661,6 +1667,8 @@ Write a function to recursively compute the $t$-th Fibonacci number for any $t$.

16611667

Complete the following code, and test it using [this csv file](https://raw.githubusercontent.com/QuantEcon/lecture-python-programming/master/source/_static/lecture_specific/python_advanced_features/test_table.csv), which we assume that you've put in your current working directory

16621668
16631669

```{code-block} python3

1670+

:class: no-execute

1671+
16641672

def column_iterator(target_file, column_number):

16651673

"""A generator function for CSV files.

16661674

When called with a file name target_file (string) and column number

@@ -1681,6 +1689,8 @@ for date in dates:

16811689

Suppose we have a text file `numbers.txt` containing the following lines

16821690
16831691

```{code-block} none

1692+

:class: no-execute

1693+
16841694

prices

16851695

3

16861696

8

Read the original on github.com ↗