简体   繁体   中英

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.

Heres what the workflow looks like:
在此处输入图片说明

My python script looks like this:

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.

In addition to the language you have two options in your Run Script object: with input as argv and with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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