私のPython 3プログラムに問題があります。私はMac OS Xを使用しています。このコードは正しく動作しています。Python 3 - ValueError:解凍するのに十分な値がありません(期待値3、2)
# -*- coding: utf-8 -*-
#! python3
# sendDuesReminders.py - Sends emails based on payment status in spreadsheet.
import openpyxl, smtplib, sys
# Open the spreadsheet and get the latest dues status.
wb = openpyxl.load_workbook('duesRecords.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')
lastCol = sheet.max_column
latestMonth = sheet.cell(row=1, column=lastCol).value
# Check each member's payment status.
unpaidMembers = {}
for r in range(2, sheet.max_row + 1):
payment = sheet.cell(row=r, column=lastCol).value
if payment != 'zaplacone':
name = sheet.cell(row=r, column=2).value
lastname = sheet.cell(row=r, column=3).value
email = sheet.cell(row=r, column=4).value
unpaidMembers[name] = email
# Log in to email account.
smtpObj = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtpObj.ehlo()
smtpObj.login('[email protected]', '1234')
# Send out reminder emails.
for name, email in unpaidMembers.items()
body = "Subject: %s - przypomnienie o platnosci raty za treningi GIT Parkour. " \
"\n\nPrzypominamy o uregulowaniu wplaty za uczestnictwo: %s w treningach GIT Parkour w ." \
"\n\nRecords show that you have not paid dues for %s. Please make " \
"this payment as soon as possible."%(latestMonth, name, latestMonth)
print('Sending email to %s...' % email)
sendmailStatus = smtpObj.sendmail('[email protected]', email, body)
if sendmailStatus != {}:
print('There was a problem sending email to %s: %s' % (email,
sendmailStatus))
smtpObj.quit()enter code here
問題は、forループに次の値を追加しようとしているときに始まります。この行で
Traceback (most recent call last):
File "sendDuesEmailReminder.py", line 44, in <module>
for name, email, lastname in unpaidMembers.items():
ValueError: not enough values to unpack (expected 3, got 2)
これは、関数 'unpaidMembers.items()'がタプルの形で3つの項目を返さないことを意味します。その値を出力して、どのような戻り値が得られるのかを調べてみましょう: 'print unpaidMembers.items()' –
あなたのコードがあなたのトレースバックに合っていません。コードでは問題は修正されていますが、 ':'がありません。 –
2つのアイテムを含むタプルを3つの異なるアイテムに解凍しようとしているようです。 @ CarlsMitjansのように、 'unpaidMembers.items()'が返す値を出力してみてください。 3つの項目にするには、追加の処理が必要な場合があります。 –