繁体   English   中英

如何在Alfred Workflows中将参数传递给Python脚本

[英]How to pass arguments to Python script in Alfred Workflows

我试图将{query}参数传递给我的python脚本(python newbie),以便我可以创建一个非常简单的计算。

以下是工作流程的样子:
在此处输入图片说明

我的python脚本如下所示:

query="{query}"

x = float(query)/60

y = x*100

print "%.2f" % x, "%.2f" % y

但是,当我运行它时,调试会返回此错误:

[2018-10-13 21:56:25][ERROR: action.script]
Traceback (most recent call last):
  File "/Users/Imran/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Scripts/A4A451B6-E747-4D1C-A957-431E755787A5", line 3, in <module>
    x = float(query)/60
ValueError: could not convert string to float: {query}

我该如何解决? 我希望能够执行bill 30来为我返回百分比计算。

除了语言之外,您的Run Script对象中还有两个选项: with input as argvwith input as {query}

如果选择了第一个选项,则代码应为:

import sys

query = sys.argv[1]

sys.stdout.write(query)

x = float(query)/60

y = x*100

print "%.2f" % x, "%.2f" % y

在第二种情况下,您的代码应为:

import sys

query = "{query}"

sys.stdout.write(query)

x = float(query)/60

y = x*100

print "%.2f" % x, "%.2f" % y

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM