如何识别我的程序的打印结果,以便我可以发送给自己

时间:2018-06-15 20:50:29

标签: python smtp twilio

我是Python的新手,我刚写了一个小程序,它会从列表中随机选择我的日常任务。我想每天早上使用Twilio或电子邮件将结果发送给自己(我尚未确定哪个)。我遇到的问题是我不知道如何识别程序的打印结果,因为结果本身不会出现在IDE中,只出现在shell中。我知道这是一个完全没有问题的问题,但我应该如何确定程序中我希望通过电子邮件发送给自己的结果?

import random
todo = ['one chapter of nonfiction', 'one chapter of math', '30 minutes of songwriting', 'one lesson of Python', '30 minutes of game design', 'one chapter of nonfiction']
book = ['Cosmos', 'A Brief History of Time', 'The Universe in a Nutshell', 'The Origin of Species', '30-Second Mythology', 'The Cartoon Guide to Physics', 'Mankind: The Story of All of Us', 'Murderous Minds', 'Frauds, Myths, and Mysteries', 'Kraken', 'Behaviourism: Classic Studies', 'Philosophy Questions and Answers', 'Ethics', 'The Potter\'s Freedom', 'The Essential Jung', 'The Institutes of Christian Religion', 'On Writing', 'Writing Better Lyrics', 'This Book Will Make You Think', 'Plato\'s Podcasts', 'The 15-Minute Psychologist', 'Philosophy: Who Needs It?', 'The Farther Reaches of Human Nature', 'Exploring the Deep Frontier', 'Picture Atlas of Our Universe', 'Walden', 'The Basic Writings of Bertrand Russell', 'Meditations', 'The Republic', 'The Dialogues of Socrates', 'On Liberty']
print('Good morning!')
todos = random.choice(todo)
books = random.choice(book)
print('Your activity today is %s.' % todos)
if todos == 'one chapter of nonfiction':
    print ('You will read one chapter from "%s."' % books)
print ('Have a great day!')

Here's what the shell prints out for me

1 个答案:

答案 0 :(得分:0)

如果您只想通过电子邮件将结果发送给自己,请将结果存储在变量中,而不是将其打印出来。例如。 结果='您今天的活动是{}'。format(待办事项)