有一门课,老师叫写报告,还要有字数限制,在还没开始写报告就想怎么查字数啊?

碰巧,前几天看python就写了个小程序。

#! /usr/bin/python
#
coding=UTF-8

import sys

# 统计一个文件中字符个数
def wc(file_name):
fo
= open(file_name);
count
= 0;
for line in fo:
count
+= len(line.decode("UTF-8"));

fo.close();
return count;

for arg in sys.argv[1:]:
count
= wc(arg);
print count, arg;

posted on 2011-05-31 15:45  yongmou-  阅读(2320)  评论(0编辑  收藏  举报