Python 07 Files
Python 07 Files
Python 07 Files
– open
http://www.py4inf.com/code/mbox-short.txt
CT010-3-1 Fundamentals of Software Development Python Files I/O
Opening a File
http://docs.python.org/lib/built-in-funcs.html
CT010-3-1 Fundamentals of Software Development Python Files I/O
What is a Handle?
From: zqian@umich.edu
From: rjlowe@iupui.edu
...
• We can
convienently
skip a line by fhand = open('mbox-short.txt')
for line in fhand:
using the line = line.rstrip()
if not line.startswith('From:'):
continue continue
print(line)
statement
• Secondary storage
• Opening a file - file handle
• File structure - newline character
• Reading a file line-by-line with a for loop
• Searching for lines
• Reading file names
• Dealing with bad files