简体   繁体   English

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

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

I am trying to pass the {query} parameter to my python script (python newbie) so I can create a really simply calculation. 我试图将{query}参数传递给我的python脚本(python newbie),以便我可以创建一个非常简单的计算。

Heres what the workflow looks like: 以下是工作流程的样子:
在此处输入图片说明

My python script looks like this: 我的python脚本如下所示:

query="{query}"

x = float(query)/60

y = x*100

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

However when I run it my debug returns this error: 但是,当我运行它时,调试会返回此错误:

[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}

How can I resolve this? 我该如何解决? I want to be able to run bill 30 to return a percentage calculation for me. 我希望能够执行bill 30来为我返回百分比计算。

In addition to the language you have two options in your Run Script object: with input as argv and with input as {query} . 除了语言之外,您的Run Script对象中还有两个选项: with input as argvwith input as {query}

If you have the first option selected your code should be this: 如果选择了第一个选项,则代码应为:

import sys

query = sys.argv[1]

sys.stdout.write(query)

x = float(query)/60

y = x*100

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

In the second case your code should be this: 在第二种情况下,您的代码应为:

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