lecture20

lecture20 - Caltech CS 1: Fall 2010 Lecture 20 : December...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Caltech CS 1: Fall 2010 Lecture 20 : December 1, 2010 Advanced topics, part 2 Caltech CS 1: Fall 2010 Advanced topics, lecture 1 recursion first-class functions lambda expressions higher-order functions map , filter , reduce Caltech CS 1: Fall 2010 Advanced topics, lecture 2 command-line arguments list comprehensions iterators generators Course wrap-up Caltech CS 1: Fall 2010 This is the last lecture! Assignment 8 will not use min grading You'll only have until Thursday the 9 th to do rework The final should be ready by Friday due Thursday the 9 th at 6 PM Will have one final ombuds section this Thursday, recitations on Friday Friday recitations: final review Caltech CS 1: Fall 2010 There is a course feedback form in addition to the lecture feedback form The course feedback form is not optional counts as your daily quiz grade for the lecture Caltech CS 1: Fall 2010 Most of the time, we've been running programs in one of two ways: 1. importing a module directly into WingIDE and running it there 2. running it from the terminal command line However, this is a very limited way of running programs Sometimes we need to pass information to the program at the moment we run it Caltech CS 1: Fall 2010 Example: We are writing a program called capitalize.py that will take a text file create a new file which has the same contents as the original file, but capitalized How do we write this program so that it works from the command line? Caltech CS 1: Fall 2010 Given what we know now, we would probably write it using raw_input to get the name of the original file and the name of the file we want to write, e.g. % python capitalize.py Name of input file: infile.txt Name of output file: outfile.txt and the program would read from the input file infile.txt and write capitalized text to the output file outfile.txt Caltech CS 1: Fall 2010 An alternative (and simpler) approach is to make the names of the input and output file into command-line arguments : % python capitalize.py infile.txt outfile.txt and the program will work the same way, without the calls to raw_input Caltech CS 1: Fall 2010 % python capitalize.py infile.txt outfile.txt This entire line (which runs python on the program file capitalize.py ) is called a command-line i.e. a line containing a command The command-line is a feature of the terminal's command interpreter, not of Python However, Python can access the command- line from inside a Python program command-line Caltech CS 1: Fall 2010 % python capitalize.py infile.txt outfile.txt The command part can be viewed as just python or Python and the program that Python runs ( capitalize.py ) we will consider the command to be the latter ( python capitalize.py ) command Caltech CS 1: Fall 2010 % python capitalize.py infile.txt outfile.txt Anything that comes after the command are the command-line arguments...
View Full Document

This note was uploaded on 02/22/2011 for the course CS 1 taught by Professor Pinkston,d during the Fall '08 term at Caltech.

Page1 / 70

lecture20 - Caltech CS 1: Fall 2010 Lecture 20 : December...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online