#统计文件中单词个数
"""
第一步:将文件中的内容按行读取
第二步,将每一行的内容按照逗号分隔成短句
第三步,将每一个短句按空格分隔
第四步,最后分隔出来的字符串如果为纯字母或者带有非字母字符,则单词数量+1
"""
import re
count=0
with open("e:\test\b.txt","r") as fp:
for line in fp.readlines():
for i in line.split(","):
for j in i.split():
if j.isalpha():
count+=1
if re.search("W",j):
count+=1
print j
print count
#随机生成测试号码
#encoding=utf-8
import random
def RanCreatePhoneNumber(path,num):
fp=open(path,"w")
resultlist=[]
n=0
while n<num:
i = random.randint(17097999999,17098999999)
if i in resultlist:
continue
else:
resultlist.append(i)
fp.write(str(i)+"
")
n+=1
fp.close()
print RanCreatePhoneNumber("d:\PhoneNumber5.txt",200000)
#简单加密,输出字符串中每一个字母后四位的字母,比如a,则输出e,输入W,则输出A,非字母不作处理
#encoding=utf-8
def Encryption(s):
result=[]
if isinstance(s,(str,unicode,basestring)):
for i in s:
if ord(i)<=85 and ord(i)>64:
result.append(chr(ord(i)+4))
elif ord(i)<=117 and ord(i)>96:
result.append(chr(ord(i)+4))
elif ord(i)>86 and ord(i)<90:
result.append(chr(ord(i)-22))
elif ord(i)>118 and ord(i)<122:
result.append(chr(ord(i)-22))
else:
result.append(str(i))
return "".join(result)
print Encryption("YIYdakh^*{} ^%")