現在、私はこれらを3つの別々のメッセージに分解しています。 しかし、私はそれが単一の 'msg'である必要があります。これを単一の 'msg'変数にどのように組み合わせるのですか?
def dateDiffInSeconds(date1, date2):
timedelta = date2 - date1
return timedelta.days * 24 * 3600 + timedelta.seconds
def daysHoursMinutesSecondsFromSeconds(seconds):
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
return (days, hours, minutes, seconds)
injustice2 = datetime.strptime('2017-05-15 23:01:00', '%Y-%m-%d %H:%M:%S')
fridaythe13th = datetime.strptime('2017-05-25 23:01:00', '%Y-%m-%d %H:%M:%S')
shadowofwar = datetime.strptime('2017-08-21 23:01:00', '%Y-%m-%d %H:%M:%S')
now = datetime.now()
msg = (
'**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Injustice 2**.'
) % daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, injustice2))
msg2 = (
'**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Friday the 13th: The Game**.'
) % daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, fridaythe13th))
msg3 = (
'**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Middle-earth: Shadow of War**.'
) % daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, shadowofwar))
私はこれを試してみたが、その後、私は得る「はTypeError:フォーマット文字列のための引数が足りません」と。私はこれが私が十分によく理解していないという単純な問題でなければならないことを知っています。どんな助けもありがとう。
msg = (
'**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Injustice 2**.'
'**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Friday the 13th: The Game**.'
'**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Middle-earth: Shadow of War**.'
) % daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, injustice2)), daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, fridaythe13th)), daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, shadowofwar))
長さ3を文字列に追加します。 – Grimmy