Commit 95e60b1e authored by Valentina's avatar Valentina

Merge branch 'msleigh-fix-code-zip' into gh-pages

parents 14c7b07c 19a89ed8
......@@ -468,7 +468,7 @@ print("With known last position:", sond)
sond = months[8:len(months)]
print("Using len() to get last entry:", sond)
sond = months[8:]
("Omitting ending index:", sond)
print("Omitting ending index:", sond)
~~~
{: .python}
......
......@@ -28,12 +28,12 @@ while `?` matches any one character.
We can use this to get the names of all the CSV files in the current directory:
~~~
print(glob.glob('data/inflammation*.csv'))
print(glob.glob('inflammation*.csv'))
~~~
{: .python}
~~~
['data/inflammation-05.csv', 'data/inflammation-11.csv', 'data/inflammation-12.csv', 'data/inflammation-08.csv', 'data/inflammation-03.csv', 'data/inflammation-06.csv', 'data/inflammation-09.csv', 'data/inflammation-07.csv', 'data/inflammation-10.csv', 'data/inflammation-02.csv', 'data/inflammation-04.csv', 'data/inflammation-01.csv']
['inflammation-05.csv', 'inflammation-11.csv', 'inflammation-12.csv', 'inflammation-08.csv', 'inflammation-03.csv', 'inflammation-06.csv', 'inflammation-09.csv', 'inflammation-07.csv', 'inflammation-10.csv', 'inflammation-02.csv', 'inflammation-04.csv', 'inflammation-01.csv']
~~~
{: .output}
......@@ -49,7 +49,7 @@ If we want to start by analyzing just the first three files in alphabetical orde
import numpy
import matplotlib.pyplot
filenames = sorted(glob.glob('data/inflammation*.csv'))
filenames = sorted(glob.glob('inflammation*.csv'))
filenames = filenames[0:3]
for f in filenames:
print(f)
......@@ -115,7 +115,7 @@ where the maxima are a bit less regular, but the minima are consistently zero.
> > import numpy
> > import matplotlib.pyplot
> >
> > filenames = glob.glob('data/inflammation*.csv')
> > filenames = glob.glob('inflammation*.csv')
> >
> > data0 = numpy.loadtxt(fname=filenames[0], delimiter=',')
> > data1 = numpy.loadtxt(fname=filenames[1], delimiter=',')
......@@ -137,7 +137,7 @@ where the maxima are a bit less regular, but the minima are consistently zero.
> Use each of the files once to generate a dataset containing values averaged over all patients:
>
> ~~~
> filenames = glob.glob('data/inflammation*.csv')
> filenames = glob.glob('inflammation*.csv')
> composite_data = numpy.zeros((60,40))
> for f in filenames:
> # sum each new file's data into as it's read
......
......@@ -36,7 +36,7 @@ This program does exactly what we want - it prints the average inflammation per
for a given file.
~~~
$ python code/readings_04.py --mean data/inflammation-01.csv
$ python ../code/readings_04.py --mean inflammation-01.csv
5.45
5.425
6.1
......@@ -50,14 +50,14 @@ $ python code/readings_04.py --mean data/inflammation-01.csv
We might also want to look at the minimum of the first four lines
~~~
$ head -4 data/inflammation-01.csv | python code/readings_04.py --min
$ head -4 inflammation-01.csv | python ../code/readings_04.py --min
~~~
{: .bash}
or the maximum inflammations in several files one after another:
~~~
$ python code/readings_04.py --max data/inflammation-*.csv
$ python ../code/readings_04.py --max inflammation-*.csv
~~~
{: .bash}
......@@ -149,7 +149,7 @@ By convention this function is usually called `main`,
though we can call it whatever we want:
~~~
$ cat readings_01.py
$ cat ../code/readings_01.py
~~~
{: .bash}
......@@ -172,7 +172,7 @@ and the name of the file to process from `sys.argv[1]`.
Here's a simple test:
~~~
$ python readings_01.py inflammation-01.csv
$ python ../code/readings_01.py inflammation-01.csv
~~~
{: .bash}
......@@ -181,7 +181,7 @@ but haven't actually called it.
Let's add a call to `main`:
~~~
$ cat readings_02.py
$ cat ../code/readings_02.py
~~~
{: .bash}
......@@ -204,7 +204,7 @@ if __name__ == '__main__':
and run that:
~~~
$ python readings_02.py inflammation-01.csv
$ python ../code/readings_02.py inflammation-01.csv
~~~
{: .bash}
......@@ -342,7 +342,7 @@ $ cat small-01.csv
{: .output}
~~~
$ python readings_02.py small-01.csv
$ python ../code/readings_02.py small-01.csv
~~~
{: .bash}
......@@ -380,7 +380,7 @@ Here's our changed program
`readings_03.py`:
~~~
$ cat readings_03.py
$ cat ../code/readings_03.py
~~~
{: .bash}
......@@ -403,7 +403,7 @@ if __name__ == '__main__':
and here it is in action:
~~~
$ python readings_03.py small-01.csv small-02.csv
$ python ../code/readings_03.py small-01.csv small-02.csv
~~~
{: .bash}
......@@ -436,7 +436,7 @@ These always appear before the names of the files,
so we could just do this:
~~~
$ cat readings_04.py
$ cat ../code/readings_04.py
~~~
{: .bash}
......@@ -470,7 +470,7 @@ if __name__ == '__main__':
This works:
~~~
$ python readings_04.py --max small-01.csv
$ python ../code/readings_04.py --max small-01.csv
~~~
{: .bash}
......@@ -499,7 +499,7 @@ before doing any processing,
so that the program fails fast:
~~~
$ cat readings_05.py
$ cat ../code/readings_05.py
~~~
{: .bash}
......@@ -546,7 +546,7 @@ and so on.
Let's experiment in another script called `count_stdin.py`:
~~~
$ cat count_stdin.py
$ cat ../code/count_stdin.py
~~~
{: .bash}
......@@ -569,7 +569,7 @@ but we can do almost anything with it that we could do to a regular file.
Let's try running it as if it were a regular command-line program:
~~~
$ python count_stdin.py < small-01.csv
$ python ../code/count_stdin.py < small-01.csv
~~~
{: .bash}
......@@ -581,7 +581,7 @@ $ python count_stdin.py < small-01.csv
A common mistake is to try to run something that reads from standard input like this:
~~~
$ python count_stdin.py small-01.csv
$ python ../code/count_stdin.py small-01.csv
~~~
{: .bash}
......@@ -600,7 +600,7 @@ so we don't actually need to change `process`.
Only `main` changes:
~~~
$ cat readings_06.py
$ cat ../code/readings_06.py
~~~
{: .bash}
......@@ -641,7 +641,7 @@ if __name__ == '__main__':
Let's try it out:
~~~
$ python readings_06.py --mean < small-01.csv
$ python ../code/readings_06.py --mean < small-01.csv
~~~
{: .bash}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment