我正在尝试用Python编写程序,使用Twitter自动使用用户的名称和电子邮件填充电子邮件。这是我试图用来查找和替换关键字的定义('$ NAME','$ EMAIL'等)
def modifyEmail():
email = open(destinationTitle, 'r+')
for line in email:
email.write(line.replace('$NAME',account.name))
email.write(line.replace('$EMAIL',email))
email.write(line.replace('$USRNAME',targetHandle))
email.write(line.replace('$PROFILEIMG',account.profile_image_url))
email.write(line.replace('$PROFILEURL',account.url))
return
我正在使用python-twitter包装器,用户输入电子邮件地址和Twitter用户名,但图片,网址和名称是从Twitter帐户中取出的(因此帐号,帐号,帐号等)
这是destinationTitle
来自的地方:
destinationTitle = str("emails/"+account.name+" - Generated Spear.emlx")
shutil.copy('email.emlx', destinationTitle)
modifyEmail()
我遇到的问题是它没有用正确的值替换$ words,而是在底部做了一件奇怪的事情,它将电子邮件的下半部分重复了5次。这是一个小例子,在这个例子中,它随机替换了一个$ EMAIL,我不知道为什么?! (我正在使用Twitter电子邮件进行测试):
[...]
From: Twitter <password@twitter.com>
From: Twitter <password@twitter.com>
From: Twitter <password@twitter.com>
To: Adam <$EMAIL>
To: $NAME <me@adam.com>
To: $NAME <$EMAIL>
To: $NAME <$EMAIL>
To: $NAME <$EMAIL>
Subject: Reactivate your Twitter account
Subject: Reactivate your Twitter account
Subject: Reactivate your Twitter account
Subject: Reactivate your Twitter account
Subject: Reactivate your Twitter account
MIME-Version: 1.0
MIME-Version: 1.0
MIME-Version: 1.0
[...]