python统计文件中文字数量的方法,python统计,虽然python自带有c
python统计文件中文字数量的方法,python统计,虽然python自带有c
虽然python自带有count()统计方法,但我还是自己动手写了一个方法来统计文件中的字数量。
自己写的python统计文件中字数量的方法,源码如下(供参考):需要首先导入python string模块中的方法。
from string import *def countWords(s): words=split(s) return len(words) #returns the number of wordsfilename=open("welcome.txt",'r') #open an file in reading mode#www.iplaypy.comtotal_words=0for line in filename: total_words=total_words + countWords(line) #counts the total wordsprint total_words
相关文章推荐:Python统计代码行数的快捷方法
编橙之家文章,
相关内容
- python获取android源代码,pythonandroid,要在windows环境下
- 如何使用tornado运行Django,tornado运行django,如何使用tor
- Python global本地与全局命名空间的使用方法示例,pytho
- python方法获取CGI服务器中环境变量的实现,pythoncgi,py
- Python解析HTML表格方法源码示例,python解析源码示例,编
- 用Python来判断过剩数的方法示例,python过剩数示例,在用
- Python迭代方法求素数的源码示例,python素数,python很多方
- python自动判读素数返回True/False方法,pythonfalse,素数检测
- Python完成计算三维矢量幅度的方法源码,python矢量,关于
- Python方法下载yahoo财经股市信息源码,python财经股市,
评论关闭