fileinput confusion :( - Python

Import fileinput, sys, string, os def main(): searchterm = sys.argv[1] targetdir = os.listdir(sys.argv[2]) for item in targetdir: if not('.txt' in item): targetdir.remove(str(item)) print item, "removed" else: print item print targetdir for line in fileinput.input(targetdir): num_matches = string.count(line, searchterm) if num_matches: # a nonzero count means there was a match print "found '%s' %d times in %s on line %d." % (searchterm, num_matches, fileinput.filename(), fileinput.


What Is Fileinput Module - Bookshelf

Tender is the night

Tender is the night

A story of Americans living on the French Riviera in the 1930s is a portrait of psychological disintegration as a wealthy couple supports friends and hangers-on ...

The World is Flat, a Brief History of the Twenty-First Century

The World is Flat, a Brief History of the Twenty-First Century

The New York Times columnist offers a concise and compelling history of globalization, discussing a wide range of economic and political topics and issues, from ...

Heaven is for Real, A Little Boy's Astounding Story of His Trip to Heaven and Back

Heaven is for Real, A Little Boy's Astounding Story of His Trip to Heaven and Back

Heaven Is for Real is the true story of the four-year old son of a small town Nebraska pastor who during emergency surgery slips from consciousness and enters ...

Everything is illuminated, a novel

Everything is illuminated, a novel

Hilarious, energetic, and profoundly touching, a debut novel follows a young writer as he travels to the farmlands of eastern Europe, where he embarks on a ...

U is for undertow

U is for undertow

Hired by a preppy college dropout to discern the fate of a 4-year-old girl who disappeared more than 20 years earlier, Kinsey Millhone investigates the young ...

Everyday Information Directory


10.2. fileinput — Iterate over lines from multiple input ...
Source code: Lib/fileinput.py. This module implements a helper class and functions to ... The following function is the primary interface of this module: ...

The fileinput module
Example: Using the fileinput module to loop over a text file ... My provider is learning Python and trying to duplicate his old PowerBASIC console program. ...

Doug Hellmann: PyMOTW: fileinput
PyMOTW: fileinput. To start this series, let's take a look at the fileinput module, a very useful module for ... If the list is empty, the module reads data from standard input. ...

Python - The fileinput Module
A single file name is also allowed in addition to a list of file ... The re module provides the pattern matching, and the fileinput module makes searching ...

fileinput
fileinput. Updated 2003-01-30 11:29:19 ? [What is the status of this tcllib module? ... Getting started. What is Tcl? What is Tk? Getting Tcl/Tk. Getting help ...