Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Variable Scope in Python within Generator Expressions #388

Open
melv33n opened this issue Dec 9, 2024 · 2 comments
Open

Issue with Variable Scope in Python within Generator Expressions #388

melv33n opened this issue Dec 9, 2024 · 2 comments

Comments

@melv33n
Copy link

melv33n commented Dec 9, 2024

I am facing an issue in Python where variables within generator expressions (such as all(...) or list comprehensions) are not accessible unless declared globally. For instance, in all(row[column] == fieldData for row in eventsList), both column and eventsList are not accessible in that context, resulting in the exception: name 'eventsList' is not defined. Does anyone know how to solve this without declaring the variables globally?

This won't work:

column = 'some_column'
fieldData = 'expected_value'
eventsList = [{'some_column': 'expected_value'}, {'some_column': 'other_value'}]

if all(row[column] == fieldData for row in eventsList):
    print("All rows match")
else:
    print("Not all rows match")

but will do if I append global column, fieldData, eventsList at the beggining

@frikky
Copy link
Member

frikky commented Dec 12, 2024

I am facing an issue in Python where variables within generator expressions (such as all(...) or list comprehensions) are not accessible unless declared globally. For instance, in all(row[column] == fieldData for row in eventsList), both column and eventsList are not accessible in that context, resulting in the exception: name 'eventsList' is not defined. Does anyone know how to solve this without declaring the variables globally?

This won't work:

column = 'some_column'
fieldData = 'expected_value'
eventsList = [{'some_column': 'expected_value'}, {'some_column': 'other_value'}]

if all(row[column] == fieldData for row in eventsList):
    print("All rows match")
else:
    print("Not all rows match")

but will do if I append global column, fieldData, eventsList at the beggining

Hey!

Is this in the Execute Python function, Liquid or with a custom app?

It indeed must have something to do with local vs global scopes if the execute python function 🤔

@melv33n
Copy link
Author

melv33n commented Dec 13, 2024

Is this in the Execute Python function, Liquid or with a custom app?

It's in Execute Python Function inside Shuffle-tools app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants