- 13 December
- Wrapup, final, last chance to ask about Homework 6. Contrasting the computing times of programs: lists versus dictionaries, and calculating Fibonacci numbers.
- 11 December
- 9 December
Continue with examples from Tk GUI.
- 6 December
Start GUIs in Python with Tkinter and Tix. Notes are Tk GUI page.
- 4 December
Problem-solving exercise. Notes: 4dec.pdf
- 2 December
- 22 November
- 20 November
- 18 November
Networking continued: writing a Web Server in Python (involves a bit of HTML, write methods and modules). Notes: 18nov.pdf
- 15 November
- Command-line arguments to Python scripts, the subprocess module, try and except, and
start of Chapter 26 on Network modules in Python. Notes: 15nov.pdf
- 13 November
The three standard files via the sys module: sys.stdin, sys.stdout, sys.stderr. Running scripts as commands, getting parameters from sys.argv. The Pipeline (Unix) convention (now also used in Windows PowerShell). As a motivating example,
Notice how what foo does is similar to the csv module's Reader and DictReader functions.
Then the lectures had examples showing command line redirection, featuring a program one.py that writes a thousand lines, and another program two.py which reads lines and accumulates the sum of the lengths of the lines. These are examples of redirection and using a pipe to connect both programs:
$ python one.py > data.txt $ python two.py < data.txt $ python one.py | python two.py
- 11 November
Continue from 8nov.pdf -- how to open files, read from files, write to files. The difference between binary and text files (some extra material is on the Bytes and Binary page). It's also useful to know about the os module and the sys module, which are used frequently for input and output. Here is a useful example using the os module (which you can look up):
- 8 November
Interaction (motivating program using graphics would be tdemo_nim.py) Simple scripts that use Python's input() function, which motivates topics of data validation. Study material for input() comes from Chapter 25. Lecture notes: 8nov.pdf (only the first five pages covered on Friday).
- 6 November
A brief look at drawing in Python. Explore a few of the features in Python's turtle module, mentioned in Chapter 24 (which is not required reading for this semester). Fancy examples follow the turtle demo. For Python3, here is the turtledemo.zip (for other versions of Python, the demo is slightly different, and can be downloaded). A different way of drawing, using the "teken" module, is found in the stepper help. Lecture notes: 6nov.pdf
- 5 November
Exam Review: 5nov.pdf
- 4 November
Recursion and loops: 4nov.pdf
- 1 November
Search patterns, the "break" and "continue" statements: 1nov.pdf
- Challenge problem: Suppose Catalog is a list of strings. Write a function munge(Catalog) that changes Catalog by concatenating the alphabetically smallest string to each item that comes before it in Catalog. Example: Second challenge problem: let Vector be a list of numbers, at least one of which is negative. Write a function bias(Vector) that changes Vector by adding the first negative number to each item that comes before it in Vector. Example:
- Challenge problem: Suppose Catalog is a list of strings. Write a function munge(Catalog) that changes Catalog by concatenating the alphabetically smallest string to each item that comes before it in Catalog. Example:
- 30 October
Review the Accumulation Pattern: 30oct.pdf More discussion of current homework.
- 29 October
More examples to help with homework: 29oct.pdf
- 28 October
Examples of loops focused on current homework: 28oct.pdf
- 25 October
More examples with loops, how to synthesize a loop, loops over two sequences, and trying some problems. Notes: 25oct.pdf
- 23 October
- 21 October
Review the assert statement. Continue chapter 20, with emphasis on pseudocode. Most of the lecture is problem-solving, from specification to pseudo-code, and then to Python. Notes: 21oct.pdf (but since loops haven't been introduced yet, a big part of the notes will be skipped)
- 18 October
Connected to modules is the topic of documentation in Python (Chapter 20). Part of this lecture continues coverage of modules, then also covers some topics on documentation. Notes: 18oct.pdf
- 16 October
Look at some examples using Python Tutor
- 14 October
Review list methods append, extend, sort, reverse (which indirectly assign to list slices). Then cover the concept of alias, the id() function, and the "is" operator. Notes: 14oct.pdf
- 11 October
Finish Chapter 15. Notes: 11oct.pdf
- 9 October
The assignment statement: Python variables. Start Chapter 15. Notes: 9oct.pdf.
- 7 October
- 4 October
Final chance to ask about homework (in class). Begin covering Tail Recursion (Chapter 14). Time permitting, lecture notes will be 4oct.pdf.
- 2 October
- Which of these two comprehensions (which do exactly the same thing) is more sensible?
- 30 September
Continue with problem-solving examples and the homework, also illustrating a word problem (counting unique words in a document by dictionary comprehension). Lecture notes in 30sep.pdf. Supplements to the lecture show some other techniques by video, which might well be useful for the homework:
- 27 September
Continue with 25sep.pdf and consider some problem-solving examples. A look at some of the homework problems, discussing what can be used from this chapter to help solve the problems there.
- 25 September
Important Lecture: begin the chapter on functions of lists, transformations of lists, customized lists, and more. The thinking moves from single data items (strings, lists, numbers, etc) to mass operations on collections of data. The main point of the lecture is to show comprehension syntax in Python. The lecture will have part of 25sep.pdf (but will be continued on Friday). The comprehension topic is integral to the current homework, and that will be emphasized. Supplementing this lecture are some youtube videos on functions of lists, all and any, map and filter, and the zip function.
- 23 September
Finish justification of elif statement. Then, covering slice notation, split, join, and replace methods for character strings. Notes in 23sep.pdf
- 20 September
Chapter 11 (if, else, elif statements). Blocks of statements and indenting. Perils of using the tab character. Emphasizing that "return" ends the evaluation of a function. Notes in 20sep.pdf (but also, demonstration of functions in stepper).
- 18 September
Looking at keywords in both arguments and parameters. Keyword parameters. The "*" notation for parameters. A quick look at conditional logic (if/else) in function definitions. See 18sep.pdf for notes.
- 16 September
The significance of None in Python. Why 1+f(x) gets an error if the definition of f(x) forgot to return a value. Look at some skipped points in 13sep.pdf. Mixing printing and calculation.
- 13 September
Defining new functions in Python, continuing 11sep.pdf: the def statement, parameters and arguments. Showing that functions can both "return" a value be in a print() function in a script. Once a function is defined, it can be used multiple times, and even in other functions and expressions. Additional notes (not presented during the lecture) are in 13sep.pdf, to be seen Monday.
- 11 September
Finish the print/function statement (see 9sep.pdf), also mentioning long strings and the repr() function. Is there some way to minimize the unfortunate difference between the way Python2 and Python3 do printing? Yes, there is a trick.
If one of the first lines of a script (for Python2) isThe later part of the lecture introduces function definition in Python, 11sep.pdf
from __future__ import print_functionthen the script will use the Python3-style print function, even though the script runs in Python2. In other words, you can tell Python2 to use the Python3 style of printing. Even interactively using Python2, you can type, as a command
>>> from __future__ import print_functionand thereafter use Python3-style print() function. (You may wonder if there is some way to let such a line automatically be part of starting Python; the answer is yes, but the technique is so various between Linux, Windows, and Mac and in such a complex way, that it can't easily be described.)
- 9 September
Introducing the print function/statement (depending on Python version). How control characters are interpreted and what they do. Other useful things to mention are the count() method and how long, multiline strings can be defined in Python. The material from 9sep.pdf will need to be continued on Wednesday 11 September.
- 6 September
More on expressions. Giving names to data. The important rule for the first part of this course: no name should be defined twice. Lecture shows how definitions are not "active" definitions, but take hold once. Looked at first two pages of 6sep.pdf
- 4 September
Start Chapter 7 - expressions in Python. How to combine multiple types and operators on a single line of Python. The method operator (uses period) and examples such as "T" in "faster".upper() --- how operators have priorities in expressions, which is crucial to understanding how Python evaluates an expression. Step-by-step expression evaluation, how to work it out on paper, as shown in the lecture. Looked at first page of 4sep.pdf as problem examples.
- 30 August
Chapter 6 - operators in Python. Announcements: first homework due date coming up (please see Homeworks, flashcard feature added to the website (see FlashCards though many of the flashcards are much ahead of current material). The lecture went through two pages of the problems in 30aug.pdf (but the third page is good study material, and if you have questions, they will be good to share in the next lecture session).
- 28 August
Important Update to Syllabus dates, times, and locations for the first two midterms have been given to us by the administration. Please reserve October 8th and November 5th evenings for these midterms. Lecture topic - Chapter 5 - Types in Python. Lecture mostly consists of interactive Python type queries and puzzles about types. See 28aug.pdf for the puzzles. On Friday 30th of August, the topic will be Chapter 6, Operators in Python (types are the "nouns" and operators are the "verbs" of Python). Extra for CS Majors only: not part of the course, but handy things in Python to work with binary and hexadecimal numbers here.
- 27 August
(Discussion Section) Computing facilities for Python. Location of departmental computers, how to log in and run Python, passwords and other basics. How to log in to CSG computers remotely (following instructions by the Remote Login page's pointers). Then, how to run IDLE on Linux, and how to run IDLE on Windows (both for CSG machines). If you install Python on your own computer, the methods would be different.
- 26 August
Basic course orientation, policies, and the Syllabus. Note that Chapter 4 is available on ICON (which covers some topics of the discussion sections on 27th August), and Chapter 5 is assigned for the lecture of 28 August. Please read Chapter 5 before you come to the lecture on Wednesday the 28th.