在变量引号显示的参数中使用变量时的 Python 子过程



我有这段代码。

scrcpy_subprocess = subprocess.Popen([scrcpy_executable, '--serial', device_selection['devices']], stdin=None, stdout=console_log, stderr=console_log)

本节

device_selection['devices']

当程序运行时。存储在上面变量中的变量仍然包括引号。

这意味着它的结果是。。

error: failed to get feature set: device 'AQYHCE9L5LH6EMDY
' not found

有人知道解决这个问题的方法吗??

根据错误,它看起来更像是在其中包含换行符,而不是引号。

尝试

device = device_selection["devices"].strip()  # remove trailing/leading spaces
scrcpy_subprocess = subprocess.Popen(
[scrcpy_executable, "--serial", device],
stdin=None,
stdout=console_log,
stderr=console_log,
)

或者如果它真的仍然不起作用,

# remove trailing/leading spaces, then all quotes
device = device_selection["devices"].strip().replace("'", "")

最新更新