Skip to content

Commit 2084e61

Browse files
authored
fix: Correct Python code examples in inputs/outputs guide (#2096)
1 parent 68b960b commit 2084e61

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

sources/academy/platform/deploying_your_code/inputs_outputs.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,27 @@ Alternatively, when writing in a language other than JavaScript, we can create o
9090

9191
```py
9292
# index.py
93-
from apify_client import ApifyClient
94-
from os import environ
9593
import json
94+
from os import environ
95+
from apify_client import ApifyClient
9696

9797
client = ApifyClient(token='YOUR_TOKEN')
9898

9999
# If being run on the platform, the "APIFY_IS_AT_HOME" environment variable
100100
# will be "1". Otherwise, it will be undefined/None
101-
def is_on_apify ():
101+
def is_on_apify():
102102
return 'APIFY_IS_AT_HOME' in environ
103103

104104
# Get the input
105-
def get_input ():
105+
def get_input():
106106
if not is_on_apify():
107107
with open('./apify_storage/key_value_stores/default/INPUT.json') as actor_input:
108108
return json.load(actor_input)
109109

110110
kv_store = client.key_value_store(environ.get('APIFY_DEFAULT_KEY_VALUE_STORE_ID'))
111111
return kv_store.get_record('INPUT')['value']
112112

113-
def add_all_numbers (nums):
113+
def add_all_numbers(nums):
114114
total = 0
115115

116116
for num in nums:
@@ -119,9 +119,7 @@ def add_all_numbers (nums):
119119
return total
120120

121121
actor_input = get_input()['numbers']
122-
123122
solution = add_all_numbers(actor_input)
124-
125123
print(solution)
126124
```
127125

@@ -168,16 +166,16 @@ You can read and write your output anywhere; however, it is standard practice to
168166

169167
```py
170168
# index.py
171-
from apify_client import ApifyClient
172-
from os import environ
173169
import json
170+
from os import environ
171+
from apify_client import ApifyClient
174172

175173
client = ApifyClient(token='YOUR_TOKEN')
176174

177-
def is_on_apify ():
175+
def is_on_apify():
178176
return 'APIFY_IS_AT_HOME' in environ
179177

180-
def get_input ():
178+
def get_input():
181179
if not is_on_apify():
182180
with open('./apify_storage/key_value_stores/default/INPUT.json') as actor_input:
183181
return json.load(actor_input)
@@ -186,15 +184,15 @@ def get_input ():
186184
return kv_store.get_record('INPUT')['value']
187185

188186
# Push the solution to the dataset
189-
def set_output (data):
187+
def set_output(data):
190188
if not is_on_apify():
191189
with open('./apify_storage/datasets/default/solution.json', 'w') as output:
192190
return output.write(json.dumps(data, indent=2))
193191

194192
dataset = client.dataset(environ.get('APIFY_DEFAULT_DATASET_ID'))
195-
dataset.push_items('OUTPUT', value=[json.dumps(data, indent=4)])
193+
dataset.push_items([json.dumps(data, indent=4)])
196194

197-
def add_all_numbers (nums):
195+
def add_all_numbers(nums):
198196
total = 0
199197

200198
for num in nums:
@@ -203,10 +201,8 @@ def add_all_numbers (nums):
203201
return total
204202

205203
actor_input = get_input()['numbers']
206-
207204
solution = add_all_numbers(actor_input)
208-
209-
set_output({ 'solution': solution })
205+
set_output({'solution': solution})
210206
```
211207

212208
## Testing locally {#testing-locally}

0 commit comments

Comments
 (0)