#!/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()
本文出自 “奇迹的少年” 博客,转载请与作者联系!
原文地址:http://raffaelexr.blog.51cto.com/8555551/1784299