1. Computing

Top 4 Ways to Work With Files in Python

From , former About.com Guide

When computers are not reading code, they are processing data. Data is usually stored in a file. These tips show you how to do some common tasks related to files using Python.

1. Analyzing a File Line-By-Line With Python

Particularly when programming for the World Wide Web, it is frequently necessary to limit how much input data is read at a time. In this tip, I show how to read data from a file repeatedly, gradually reading and processing all of it.

2. Processing a File All-At-Once With Python

When one has plenty of programming resources to spare, it is often easier to read all of the data from a file into a dictionary. This article shows you how.

3. Moving Around in a File With Python

In my experience, one seldom has the leisure of reading data from discrete sources. Very often, one needs to read data from multiple points in a file and evaluate the results. This tip shows how to do that.

4. Reading a Single Line from a File With Python

Depending on the architecture of your program, you may need to read the same line from a file more than once or every time the program executes. If so, you should acquaint yourself with the module linecache. Here I show you how to read a single line from the middle of a file, leaving the other lines untouched.
  1. About.com
  2. Computing
  3. Python
  4. ScripTips
  5. Ways to Work With Files in Python

©2013 About.com. All rights reserved.