首页 > 解决方案 > 错误:需要以下参数:主机

问题描述

试图在python中可视化各种传感器数据的结果

我可以像 linux 命令一样在 raspberry pi 终端上看到它python Sensortag2650.py -n 5 -t 1 -T -A -H -M -B -G -K -L -P 54:6C:0E:52:F8:FC 现在我想在 python shell 上用相同的代码看到相同的结果

def main():
import time
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('host', action='store',help='MAC of BT device')
parser.add_argument('-n', action='store', dest='count', default=0,
        type=int, help="Number of times to loop data")
parser.add_argument('-t',action='store',type=float, default=5.0, help='time between polling')
parser.add_argument('-T','--temperature', action="store_true",default=False)
parser.add_argument('-A','--accelerometer', action='store_true',
        default=False)
parser.add_argument('-H','--humidity', action='store_true', default=False)
parser.add_argument('-M','--magnetometer', action='store_true',
        default=False)
parser.add_argument('-B','--barometer', action='store_true', default=False)
parser.add_argument('-G','--gyroscope', action='store_true', default=False)
parser.add_argument('-K','--keypress', action='store_true', default=False)
parser.add_argument('-L','--light', action='store_true', default=False)
parser.add_argument('-P','--battery', action='store_true', default=False)
parser.add_argument('--all', action='store_true', default=False)

arg = parser.parse_args(sys.argv[1:])

print('Connecting to ' + arg.host)
tag = SensorTag(arg.host)

输出 :

Sensortag2650.py [-h] [-n COUNT] [-t T] [-T] [-A] [-H] [-M] [-B] [-G]
                        [-K] [-L] [-P] [--all]
                        host
Sensortag2650.py: `error: the following arguments are required: host`

标签: python-3.x

解决方案


推荐阅读