Hello World in Python processor
This example shows how to use input data, data checkpoint and logger in Python processor.
Statement
In this example, we have a reversed "Hello World" string in our input data. The primary objective is to correct this string. If the correction has already been processed, we will return the data checkpoint instead.
INPUT_DATA = [{ "data": "!dlrow olleH" }]
# Check if Data Checkpoint is available
if DATA_CHECKPOINT:
log.info("Hello world string was already processed")
return [{ "data": DATA_CHECKPOINT }] # Return the data checkpoint
# If Data Checkpoint is not available, proceed with the correction
log.info("Oh no, Hello world string is reversed")
fixed_string = INPUT_DATA[0]["data"][::-1] # Reverse the input string
return [{ "data": fixed_string }] # Return the fixed string
Execution
When you execute this task, you can expect the following output:
first run:
- INFO: Oh no, Hello world string is reversed
second run:
- INFO: Hello world string was already processed
Conclusion
This Hello World showcases how to efficiently handle input data and data checkpoint within a Python script. It serves as a simple example, but the principles demonstrated here can be applied to more complex data processing tasks.