twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.06k stars 67 forks source link

None after each line in notebook mode #279

Open CoreyCorza opened 1 year ago

CoreyCorza commented 1 year ago

Hi, thanks for making this extension. It is making learning to code and documenting my process so much more enjoyable.

Is there a reason why "none" is printed after everything though? Or maybe I'm just doing something wrong and this isn't an issue/bug?

Obsidian_0j116H7gME

CoreyCorza commented 1 year ago

Also this seems to only happen in notebook mode

CoreyCorza commented 1 year ago

Sorry if this is annoying... such a small issue compared to the others that've been logged lol

twibiral commented 1 year ago

Hey, don't worry, that's normal. The notebook mode is based on the python interpreter you can use in the command line. If you enter python (or python3) on the command line, you can execute your code line-by-line or in snippets. We handle each code box as a snippet that is executed in the interpreter.

If you call a function in the interpreter, than the return value is printed in the console. E.g., paste the following line into the interpreter and in prints 6 to the console:

import math
math.factorial(3)

But if a python function does not return a object or number, then it returns None. That means if you call a function without a return value (e.g. the function below), then the interpreter returns None. At the moment, we add the None to the output of the code block. We could change this in future releases.

def f():
    pass

Until then, you can ignore the None.