【问题标题】:In Python how to use variables in call function?在 Python 中如何在调用函数中使用变量?
【发布时间】:2013-10-30 05:16:14
【问题描述】:

我在 Ubuntu 上使用 Python。 call(["xdotool", "mousemove", "500","600"])工作正常。

但是如果x=500y=600

call(["xdotool", "mousemove", "x","y"]) 不起作用。

xy的语法应该是什么?

【问题讨论】:

  • 去掉引号。 "x" 是一个字符串(包含单个字母 x)。
  • 我也试过了,但是没用。
  • @Sam 怎么样?请提供您尝试过的代码和回溯(错误):)
  • “不工作”没有帮助,唉。说出确切地发生了什么,包括任何错误消息的全文和回溯。并显示您使用的确切代码。
  • 使用str(x)str(y)

标签: python call mousemove xdotool


【解决方案1】:

这样使用

call(["xdotool", "mousemove", str(x), str(y)])

xy 是指向数据的变量。但是当你说"x""y" 时,你是在传递数据本身。

【讨论】:

【解决方案2】:

去掉引号。如果你保留引号,它将被视为一个字符串。

call(["xdotool", "mousemove", "500","600"])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    相关资源
    最近更新 更多