1
votes

I'm trying to do a simple declaration of an inputted variable to an integer, but am receiving an error:

Bargle. We hit an error creating a run python. :-( Error: Your code had an error! Traceback (most recent call last): File "/tmp/tmpXq4aAP/usercode.py", line 7, in the_function num = int(input['managers']) KeyError: 'num'

The following is the code i'm using:

num = int(input['num'])

if num >= 100 :
  big_num = true
else:
  big_num = false

return {'big_num': big_num}
5

5 Answers

3
votes

Your error is right here:

num = int(input['num'])

Change those square brackets for round brackets:

num = int(input('num'))

If you are on Python 2 you should use raw_input

num = int(raw_input('num'))
2
votes

In Zapier, the code:

input['varname']

refers to the variable that is passed in the "Code by Zapier" Action.

The error you are getting sounds to me like you have not defined the num variable prior to your code.

Also, True and False need to be capitalized.

Otherwise, see below, this setup works...

enter image description here

num = int(input['num'])

if num >= 100 :
  big_num = True
else:
  big_num = False

return {'big_num': big_num}
1
votes

Many of these answers reference the input() built in - we override that in Code by Zapier (since it literally makes zero sense to have user input on an automated script). In it's place is a dictionary defined by some fields above.

Definitely confusing for folks unfamiliar with the context of Zapier - we'll look into renaming it and just nulling the input build.

0
votes

Input is a kernel method and it can't be subscriptable , there is an syntax error change the code to like this.

num = int(input('num'))
0
votes

Within Zapier, the proper way to convert Input Data (every input into a Code Step is a String) to Integers is as follows:

num = int(input.get('num'))

or

num = int(input['num'])

If the number comes attached with a decimal, strip the unwanted characters from the String before converting to an Integer. For a number like 80.0 this would look like:

num = int(input['num'][:-2])