Accessing Airflow Variable in List format

Viewed 1236

i have this Variable on Airflow

['item_1', 'item_2']

then i get the variable

my_var = Variable.get('my_var')

and then i try to loop it like this

for var in my_var:
    print(var)

it prints the character one by one.

My question is: how do i access the list value? without printing the character one by one

1 Answers

You can store it as JSON string then use deserialize_json=True

my_var = Variable.get("my_var", deserialize_json=True)
first = my_var[0]
Related