Replies: 3 comments 13 replies
-
This is not true, keeping the last variable in scope is standard python. Maybe keeping it in scope within just the cell makes sense- but maybe frustrating if you did want the correct behavior. But this is a common complaint. what about implicitly private variables being declared: # suggested as import because it's easiest to hook into the ast
from marimo.private import i, j, k, dynamic_name
# reuse i as much as you want across cells Another suggestion (harder to implement, and less elegant) from marimo import range, enumerate, zip Where the imported behavior is what you proposed? (Users could also do Here are some other suggestions that have been mentioned before:
|
Beta Was this translation helpful? Give feedback.
-
I'm not sure if I like the dynamic imports. What about something like this? import marimo as mo
let i, j, k = mo.locals()
# use i, j, k wherever you like The AST can infer how many variables that |
Beta Was this translation helpful? Give feedback.
-
I still think that just allowing variables that are first written to (not read) in all cells where they appear would be nice and safe. #1477 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Suggestion: Scope for-loop iterator variables to their loop context
Problem
This pattern is one of the most common constructs in Python programming. Typically, the
item
variable is intended to be temporary and only meaningful within the loop's context. However, in Python, this variable persists in the namespace after the loop completes.In marimo, this behavior creates unexpected issues when the same iterator variable name is reused across different cells:
Proposed Solution
I suggest that marimo treats for-loop iterator variables as scoped to their loop context by default. This would better align with the programmer's intent, where these variables are typically meant to be temporary.
Current Workarounds
Currently, users must:
_item
to indicate temporary statusBenefits
Implementation Considerations
This could be implemented as:
Would love to hear your thoughts on this suggestion!
Beta Was this translation helpful? Give feedback.
All reactions