-
Notifications
You must be signed in to change notification settings - Fork 324
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
Allow explicit cell export (dependency) using return #1901
Comments
One could also consider a = 12
b = 42
c = a+b
return dict(c=c) Which is more explicit and allows expressions in the return (not just variable names) a = 12
b = 42
return dict(c=a+b) (while the |
Thanks for the feature suggestion. If the code will likely end up in a function, why not just start with it in a function that has a sensible name (not The |
I like the spirit of the idea, not quite sure if it's right. As for why not just start with a function? I like to work a line or two at a time progressively, inspecting variables as I go. So as I'm writing the cell I actually want all the variables exported, but then I want a clean way to turn it into a function. I wonder if a cell action that refactors it into a function would be useful? Then it doesn't have as much of a learning curve, if you don't know about it, it doesn't affect you. Plus it would help with the "oops I forgot that this one was a global variable and forgot to add it as a function argument" problem since it would know all the variables you were relying on. |
A proposal (#719) for solving this was just to write: def my_function():
"""This is my function"""
c = a + b
return c in notebook mode, which would then get written to the output file as: @app.fn
def my_function():
"""This is my function"""
c = a + b
return c With some indication in notebook mode (autonaming of the cell I think and maybe something else) that the cell is a "python function". There's a longer discord discussion about this, but if this solution fits your problem, then maybe we'll utilize this issue for discussion edit: if it wasn't clear this mode only kicks in if no "global" references are utilized- solving your issue. You could be certain everything was scoped as long as the indicator showed it was going to save in this form |
Thanks for your discussions. I took some time to think about it and experiment with writing functions right away.
Thanks for this project. |
PS: I'm on the discord so if the discussion is public and I can contribute meaningfully, let me know where it is. |
You might be interested in using the scratchpad functionality more (little notebook icon)
|
Hi, sorry for the delay, I was not working on marimo for some time. I feel however that my use of marimo is as a gigantic scratchpad (I'm writing directly python modules if it goes beyond exploratory), and I'm relying on dependencies between cells in this giant scratchpad mode. |
Description
When writing code cells that will probably end up into a function, I'd like to keep as many things as local variables. It is also the case by default in a notebook.
I'd like to be able to have a plain cell but specify what variables it exports.
Suggested solution
I'd suggest the use of return, which would replace the default return that marimo generates.
Alternative
One can use local marimo variables, which is sometimes ok, but the code becomes more difficult to change and requires modification if we want to make a (clean) function as the
_
is not recommended that case.The other solution is to introduce a function directly but its is more difficult to iterate over, it is error prone when modifying, seems less natural to people that don't know why we would do that and seems to duplicate part of the work of marimo.
The text was updated successfully, but these errors were encountered: