Я пытаюсь закодировать сценарий, который обнаруживает текущую дату и время, а затем создает на его основе папку с именем. Я получаю эту ошибку, когда я пытаюсь запустить мой код:ТипError:% d format: требуется номер, а не getset_descriptor
TypeError: %d format: a number is required, not getset_descriptor
Это мой код:
import os
import time
#import RPi.GPIO as GPIO
import logging
import sys
from datetime import datetime
d = datetime
initYear = "%04d" % (d.year)
initMonth = "%02d" % (d.month)
initDate = "%02d" % (d.day)
initHour = "%02d" % (d.hour)
initMins = "%02d" % (d.minute)ion where you wish to save files. Set to HOME as default.
# If you run a local web server on Apache you could set this to /var/www/ to make them
# accessible via web browser.
folderToSave = "/home/timelapse/timelapse_" + str(initYear) + str(initMonth) + str(initDate) + str(initHour) + str(initMins)
#os.mkdir(folderToSave)
# Set the initial serial for saved images to 1
fileSerial = 1
a = 'timefile'
# Run a WHILE Loop of infinity
while True:
if os.path.isfile(a) == False:
# Set FileSerialNumber to 000X using four digits
fileSerialNumber = "%04d" % (fileSerial)
# Capture the CURRENT time (not start time as set above) to insert into each capture image filename
hour = "%02d" % (d.hour)
mins = "%02d" % (d.minute)
# Define the size of the image you wish to capture.
imgWidth = 800 # Max = 2592
imgHeight = 600 # Max = 1944
print " ====================================== Saving file at " + hour + ":" + mins
# Capture the image using raspistill. Set to capture with added sharpening, auto white balance and average metering mode
# Change these settings where you see fit and to suit the conditions you are using the camera in
os.system("raspistill -w " + str(imgWidth) + " -h " + str(imgHeight) + " -o " + str(folderToSave) + "/" + str(fileSerialNumber) + "_" + str(hour) + str(mins) + ".jpg -sh 40 -awb auto -mm average -v")
# Increment the fileSerial
fileSerial += 1
# Wait 10 minutes before next capture
time.sleep(600)
else:
os.remove(time.txt)
os.system("sudo shutdown -h -P now")
break
print "Quitting now."
sys.exit(0)
Я думаю, что код имеет ошибку здесь:
initYear = "%04d"
Ошибка похоже, вокруг «% 04d». Любые предложения или помощь будут оценены. Заранее спасибо.
Что вы вкладываете * в * эту строку формата? Спецификации заполнителя * не проблема *. –
Это не ваша ошибка. Пожалуйста, предоставьте трассировку. – Gerrat
@MartijnPieters Я удалил «% (d.year)» с конца бит «% 04d» в надежде, что он сработает, но это не помогло. –