[root@wing python]# cat Chicken_Soup_for_the_Soul.py 
#!/usr/bin/env python
#coding=utf8
#"Chicken Soup for the Soul" Version:0.1
#author by CrazyWing,weixin:18612540627
#思想:想办法得到文本有多少行,再以行数作随机取值
import random,re
with open('jitangxin.txt','r') as f:
    file_con=f.readlines()
line_num=len(file_con)
rand_line_num=random.randint(1,line_num)
con=file_con[rand_line_num-1]
content=re.sub(r'\d*','',con)
print content

注意:被处理文件jitangxin.txt内容如下:

转载于:https://blog.51cto.com/fklinux/1980551