【发布时间】:2021-07-19 21:05:19
【问题描述】:
我想先解释一下这个应用程序/Python 程序的作用,以便您更好地理解问题。我是编程的绝对初学者,所以请放轻松,我已尽力尽可能生动地解释它。 此应用程序将用于测试 4000 台设备是否有正确的软件硬件版本和其他信息。它是如何通过网络服务器做到这一点的,每个设备都有一个将被扫描的二维码(它就像一个条形码),这个扫描的代码包含 MAC 地址和订单号。首先,当我在命令提示符下运行程序时,它应该如下所示: 我应该能够定义所需的变量是什么,因此在命令提示符中手动键入它,除了扫描代码,当我使用 2D 扫描仪并扫描将在设备外部的代码时,它会自动出现。扫描码包含设备 mac 地址(后 12 位)和订单号(前 5 位),我发现了如何剖析它并将其与网络服务器的 Mac 地址和订单号进行比较。
一旦我为订单号硬件版本软件版本等定义了所需的值,就需要将这些“所需”值与网络服务器值进行比较。 (请参阅我的 Python 代码以供参考,我通过 xml.dom 获取网络服务器值,然后将其与所需值进行比较以查看值是否正确。 到目前为止,我只在源代码中手动定义了所需的值,但我想在调用程序“C:\Users\Barry\Automate main.py”后在命令行上定义它们 我希望你们已经理解我面临的问题,我想知道是否有人可以帮助我解决这个任务我已经用谷歌搜索了很多关于这个但我不知道该怎么做。 在我上传的图片中,红色下划线的值是手动输入的,蓝色的是扫描码,当我扫描设备时会自动出现。 我用 input() 方法尝试了几件事,但是没有成功示例:
print("./productionreview -output test.csv", "--desired-orderno = ",input(), "--desired-hardwareversion = ",input(), "--desired-softwareversion = ",input()," --pc-praefix",input(), "--desired-device-type=",input(), "--scancode=", "58183#99AF0M000F9EF3F800")
这是我的代码,如果我没有使用正确的术语,请对我放轻松,我对编程世界很陌生,但这很有趣。
print("./productionreview -output test.csv", "--desired-orderno = ",input(), "--desired-hardwareversion = ",input(), "--desired-softwareversion = ",input()," --pc-praefix",input(), "--desired-device-type=",input(), "--scancode=", "58183#99AF0M000F9EF3F800")
# Desired Values
# Timestamp
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Eingabe von scancode
scancode_string = input()
scan_code_cropped_mac = scancode_string[12:]
scan_code_cropped_artikel = scancode_string[:5]
#print(scan_code_cropped_artikel)
#print(scan_code_cropped_mac)
print(scancode_string)
print("Current device information: ")
print(now)
print(100*"")
# Order number
print("Desired Order number:",d_ordernum)
print("Order number from scancode :",scan_code_cropped_artikel)
print("Ordernumber from wbm: ", ord_nmr)
if d_ordernum == ord_nmr == scan_code_cropped_artikel:
print("Order number PASS")
else:
print("Order number does not match")
print(100*"")
# Hardware version
print("Desired Hardware Version:",d_hw_version)
print("Hardware Version from wbm: ", v)
if d_hw_version == v:
print("Hardware version PASS")
else:
print("Wrong Hardware Version")
print(100*"")
# Software version
print("Desired Software Version:",d_sf_version)
print("Software Version from wbm: ", b)
if d_sf_version == b:
print("Software version PASS")
else:
print("Wrong Software Version")
print(100*"")
# Mac address
print("Mac address from scancode :",scan_code_cropped_mac)
print("Mac address from wbm: ", mac_addr)
list_of_chars = mac_addr.split(":")
mac_address_string_joined = ''.join(list_of_chars)
if scan_code_cropped_mac == mac_address_string_joined:
print("Correct MAC address")
else:
print("Fail")
print(100*"")
d_product_code = pc_praefix + "-" + d_sf_version + "-" + d_hw_version
product_code = pc_praefix + "-" + b + "-" + v
print("Desired product code: ",d_product_code )
print("Product code of current device: ", product_code)
print(100*"")
print("Desired device type:",d_dev_typ)
print("Device type from wbm: ", dev_typ)
if d_dev_typ == dev_typ:
print("Device type PASS")
else:
print("Wrong device type")
print(100*"")
我真的可以使用您的建议和示例代码家伙
【问题讨论】:
-
请考虑缩短代码以仅包含您需要帮助的特定部分并减少文本墙,因为很多人会简单地忽略它并继续前进。转至here 了解如何创建最小可重现示例。
标签: python python-3.x command-prompt argparse