Python 无法将文本输入电子邮件

Python 无法将文本输入电子邮件,python,Python,我正试图向某人发送一封电子邮件,其中包含我从网上搜集到的信息,但我无法获取要发送的内容。我一直收到空邮件。任何帮助都会很好。我试过各种不同的'and+s的数字,但我想不出来 def singaporeweather(): singaporehigh=singapore_soup.find(class_='tab-temp-high').text singaporelow=singapore_soup.find(class_='tab-temp-low').text pri

我正试图向某人发送一封电子邮件,其中包含我从网上搜集到的信息,但我无法获取要发送的内容。我一直收到空邮件。任何帮助都会很好。我试过各种不同的'and+s的数字,但我想不出来

def singaporeweather():
    singaporehigh=singapore_soup.find(class_='tab-temp-high').text
    singaporelow=singapore_soup.find(class_='tab-temp-low').text
    print('There will be highs of ' + singaporehigh + ' and lows of ' + 
    singaporelow + '.')

def singaporesuns():
    singaporesunsets=singapore_soup.find(class_='row col-sm-5')
    suns_singapore=singaporesunsets.find_all('time')
    sunset_singapore=suns_singapore[1].text
    sunrise_singapore=suns_singapore[0].text
    print('Sunrise: ' + sunrise_singapore)
    print('Sunset: ' + sunset_singapore)


def ukweather():
    ukhigh= uk_soup.find('span', class_='tab-temp-high').text
    uklow= uk_soup.find(class_='tab-temp-low').text
    print('There will be highs of ' + ukhigh + ' and lows of ' + uklow + 
    '.')

def uksuns():
    uk_humid = uk_soup.find('div', class_='row col-sm-5')
    humidity=uk_humid.find_all('time')
    sunrise_uk=humidity[0].text
    sunset_uk= humidity[1].text
    print('Sunrise: '+str(sunrise_uk))
    print('Sunset: '+str(sunset_uk))

def ukdesc():
    uk_desc=uk_soup.find('div',class_='summary-text hide-xs-only')
    uk_desc_2=uk_desc.find('span')
    print(uk_desc_2.text)`enter code here`

def quotes():
    quote_text=quote_soup.find(class_='b-qt qt_914910 oncl_q').text
    author=quote_soup.find(class_='bq-aut qa_914910 oncl_a').text
    print('Daily quote:\n' + '\"'+quote_text +'\"'+ ' - ' + author +'\n')





def message():
    print('Subject:Testing\n\n')
    print(('Morning ' + 
    nameslist[random.randint(1(len(nameslist)-1))]).center(30,'*'), 
    end='\n'*2)

    quotes()

    print('UK'.center(30,'_') + '\n')
    ukweather()
    ukdesc()
    uksuns()

    print('\n' + 'Singapore'.center(30,'_') + '\n')
    singaporeweather()
    singaporedesc()
    singaporesuns()

smtpthing.sendmail('XXX@outlook.com', 'XXX@bath.ac.uk', str(message()))

在函数中,不应将结果打印到控制台,而应使用
return
语句,以便在主程序中使用函数的结果。否则,
message()
将返回null,这就是您的电子邮件为空的原因(除非返回,否则主程序无法看到
message()
的结果)

尝试以下方法:

def singaporeweather():
    singaporehigh=singapore_soup.find(class_='tab-temp-high').text
    singaporelow=singapore_soup.find(class_='tab-temp-low').text
    return 'There will be highs of ' + singaporehigh + ' and lows of ' + 
    singaporelow + '.'
通过使用像这样的返回语句,您将能够在主程序中使用
singaporeweather()
的结果,例如:

var result = singaporeweather()
在其余方法中也使用
return
s,您将能够在函数
message()
中执行以下操作:

现在您正在返回
正文
,现在您可以在主程序中使用
消息()
的结果来正确发送电子邮件:

smtpthing.sendmail('XXX@outlook.com', 'XXX@bath.ac.uk', str(message()))

在函数中,不应将结果打印到控制台,而应使用
return
语句,以便在主程序中使用函数的结果。否则,
message()
将返回null,这就是您的电子邮件为空的原因(除非返回,否则主程序无法看到
message()
的结果)

尝试以下方法:

def singaporeweather():
    singaporehigh=singapore_soup.find(class_='tab-temp-high').text
    singaporelow=singapore_soup.find(class_='tab-temp-low').text
    return 'There will be highs of ' + singaporehigh + ' and lows of ' + 
    singaporelow + '.'
通过使用像这样的返回语句,您将能够在主程序中使用
singaporeweather()
的结果,例如:

var result = singaporeweather()
在其余方法中也使用
return
s,您将能够在函数
message()
中执行以下操作:

现在您正在返回
正文
,现在您可以在主程序中使用
消息()
的结果来正确发送电子邮件:

smtpthing.sendmail('XXX@outlook.com', 'XXX@bath.ac.uk', str(message()))

您定义了很多函数,但从未调用它们?“消息”函数(与其他函数一样)只打印内容,但不返回任何内容。您定义了很多函数,但从未调用它们?“消息”函数(与其他函数一样)只打印内容,但不返回任何内容。