You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VTS主机端Python脚本:adb触摸屏点击可变坐标格式问题

解决VTS Python脚本中可变坐标触摸屏点击的格式问题

你的代码存在两个核心问题:

  1. 直接在shell命令字符串中写入变量名(x、y、coord),系统会将其视为普通文本,不会解析为变量对应的数值
  2. coord = 528 1270 属于Python语法错误,无法用这种方式定义包含两个数值的变量,需改用元组或分开传参

以下是几种可行的正确写法:

方法1:使用f-string(Python 3.6及以上版本推荐)

x = 528
y = 1270
# 将变量值直接嵌入命令字符串
device.shell(f'input touchscreen tap {x} {y}')

方法2:使用str.format()方法

x = 528
y = 1270
device.shell('input touchscreen tap {} {}'.format(x, y))

方法3:用元组存储坐标后传参

# 用元组定义坐标变量
coord = (528, 1270)
# 方式一:通过索引取值
device.shell(f'input touchscreen tap {coord[0]} {coord[1]}')
# 方式二:解包元组传入format
device.shell('input touchscreen tap {} {}'.format(*coord))

核心逻辑是要将变量的实际数值插入到shell命令字符串中,而非直接写入变量名——shell执行命令时需要的是具体的坐标数字,而非Python变量名。

内容的提问来源于stack exchange,提问作者User3872

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 14:04:51