我有一個腳本,可以完美地打印變量(由用戶設置)。Python打印輸出到電子郵件
os.system('clear')
print "Motion Detection Started"
print "------------------------"
print "Pixel Threshold (How much) = " + str(threshold)
print "Sensitivity (changed Pixels) = " + str(sensitivity)
print "File Path for Image Save = " + filepath
print "---------- Motion Capture File Activity --------------"
我現在希望通過電子郵件發送此代碼給我自己以確認何時運行。我已在腳本電子郵件中使用email.mimieText
和multipart
。但是輸出不再只顯示相關變量的代碼。
body = """ Motion Detection Started \n Pixel Threshold (How much) = " + str(threshold) \n Sensitivity (changed Pixels) = " + str(sensitivity) \n File Path for Image Save = " + filepath """
我敢肯定這是「」」包裝,但不清楚是什麼我應該使用?
可能重複[接收和蟒蛇發送電子郵件(http://stackoverflow.com/questions/348392/receive-and-send-emails-in-python) – Aprillion
看看[ 'str.format()'](http://docs.python.org/2/library/stdtypes.html#str.format)。 – thegrinner
@deathApril問題不在於發送電子郵件,而是爲了讓字符串看起來正確。 – Cruncher