我有一个.txt
文件,其中的名称和地址以下列格式显示:
Sam, 35 Marly Road
...
...
我希望能够搜索Sam
和35 Marly Road
。
这是我到目前为止的代码:
name = input("Please insert your required Client's name: ")
if name in open('clientAddress.txt').read():
print ("Client Found")`
检查输入的ID是否在文件中可用,但它不打印该地址。如何更改它,以便找到名称并打印地址?
答案 0 :(得分:0)
作为快速解决方案 - 见下文
username = input()
with open('clientRecords.txt', 'r') as clientsfile:
for line in clientsfile.readline():
if line.startswith("%s, " % username):
print("Cient %s found: %s" % (username, line[len(username) + 2:]))
break
答案 1 :(得分:0)
简单的解决方案
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = "something@gmail.com";
$mail->Password = "PWofsomething";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
$mail->From = "something@gmail.com";
$mail->FromName = "something";
$mail->addAddress(validemail,validfirstname);
$mail->Subject = "bla bla bla";
$mail->Body = html body
if(!$mail->Send()){
echo "Message was not sent."<br />PHPMailer Error: " . $mail->ErrorInfo."<br />";
}
else{
echo 'success';
$mail->clearAddresses();
`
For循环遍历文件行,当我们发现行以所需的客户端名称开始时,我们打印地址和中断循环。