我在我的树莓派制作相机程序(代码)
import picamera
import sys
import time
question=input('do you want to take a picture(pic) take a timed picture(time) or a video(vid)')
if question=='pic':
time=0
elif question=='time':
time=1
elif question=='vid':
print ('coming soon')
sys.exit()
num=0
camera = picamera.PiCamera()
camera.start_preview()
input('press any key to take picture')
if time==1 :
print ('5')
time.sleep(1)
print ('4')
time.sleep(1)
print ('3')
time.sleep(1)
print ('2')
time.sleep(1)
print ('1')
time.sleep(1)
print ('0')
camera.capture(num)
num=num + 1
当我跑的时候,它问了
你想拍照(pic)拍摄定时照片(时间)或视频(vid)
就像我回答的那样
PIC
然后它给了我这个错误
Traceback (most recent call last):
File "/home/pi/Desktop/camera.py", line 5, in <module>
question=input('do you want to take a picture(pic) take a timed picture(time) or a video(vid)')
File "<string>", line 1, in <module>
NameError: name 'pic' is not defined
发生了什么事?
答案 0 :(得分:0)
正如Cyber在评论中所说,使用python的raw_input()函数来看待输入。
raw_input()将把STDIN中的任何内容作为STR类型,直到用户点击进入。
question = raw_input("Do you want to take a picture(pic) take a timed picture(time) or a video(vid)?")