0
我正在开发一个Django应用程序,它将在生产中的树莓派3上运行。树莓派,蟒蛇,检测操作系统
我必须知道在应用的开始,如果它的树莓运行,或者开发环境。在开发中,我使用假传感器数据而不是引脚。
到现在为止我用这个方法:
from sys import platform as _platform
test_environment = "win" in _platform or "darwin" in _platform
这是对我的PC和Mac两个工作不错,但现在我想这个网上部署到Ubuntu的网络服务器。 Raspbian也是一个linux dist,所以我需要别的东西。
这是我目前工作的解决方案,但它伤害了我内心深处。任何建议,使其更好?
try:
import RPi.GPIO as gpio
test_environment = False
except:
test_environment = True
Python中的口头禅是“先询问请求原谅后”,所以使用try除了捕获错误,而不是是否可能发生错误检查 – scotty3785