#!/usr/bin/python
import sys
import os
if len(sys.argv) == 1:
data = sys.stdin.read()
else:
try:
fn = sys.argv[1]
except IndexError:
print "please follow a argument at %s" %__file__
sys.exit()
if not os.path.exists(fn):
print "%s is not exits." %fn
sys.exit()
fd = open(sys.argv[1])
data = fd.read()
chars = len(data)
words = len(data.split())
lines = data.count('\n')
print "%(lines)s %(words)s %(chars)s" %locals()
本文转自奇迹的少年博客51CTO博客,原文链接http://blog.51cto.com/raffaelexr/1784299如需转载请自行联系原作者
liliangchun