我要删除“.”字符。当我用这个的时候
text = "Rmyname.lastname@mail.com"
text = (text.replace('.',' '))
head, sep, tail = text.partition('@')
print(head)
它工作,这是输出:Rmyname lastname
但是当加载一个外部文件并读取每一行时,它不会替换“.”字符
with open('found.txt', 'r') as csvfile:
spamreader = csv.reader(csvfile)
for row in spamreader:
head = (row[0].replace('.', ' '))
head, sep, tail = row[0].partition('@')
print(head)
这是输出:Rmyname.lastname
我怎样才能解决这个问题
将替换结果存储到变量
head
。原来的row[0]
仍然有句点。将row[0].partition('@')
更改为head.partition('@')
相关问题 更多 >
编程相关推荐