在写《简明的python教程》后面习题的时候遇到一个问题
python中的.strip(string.punctuation)把最后的字母删掉了,很疑惑
文件是txt,里面是
Jack: jackma@tom.com
Tony: tonny1981@163.com.
Lucy: lucy_1992@tom.com
Xiaoming: wangxiaoming_21cn@163.com
Zhangwei: zwpeiking@tsinghua.edu.cn.
nobody: zjhznb@qq.com
with open("string_mail.txt","r") as f:
data=f.readlines()
for string1 in data:
# string=str(string1)
# print(string1)
p_center=string1.find("@")
p2=string1.find(' ',p_center)
head=string1[p_center::-1]
p1=head.find(' ')
p1=len(head)-p1
t=string1[p1:p2]
import string
rst=t.strip(string.punctuation)
print(rst)