#!/usr/bin/env python
file_name="hello.txt"
line_counts=0
word_counts=0
char_counts=0
file=open(file_name,"r")
for line in file.readlines():
words=line.split(' ')
line_counts+=1
word_counts+=len(words)
char_counts+=len(line)
print "line_count",line_counts
print "word_count",word_counts
print "char_count",char_counts
在网上找了一些小代码,但是运行时总是出错,一怒之下就改成这个样子了