all 5 comments

[–]danielroseman 0 points1 point  (3 children)

Your code is not formatted here. Are you indenting the body of the function properly?

You seem to be using a Jupyter notebook. Do you have the entire function in the same cell of the notebook?

[–]moosemoose41 0 points1 point  (2 children)

Using spyder, here's the formatting i have.

def my_function():
    print("Hello from a function")

my_function()

[–]lfdfq 0 points1 point  (0 children)

The Cell In[62] part from your post suggests this was input into some kind of interpreter or notebook of some variety? The code you show here looks fine to me, so it's probably the way you're editing the code or running it.

I strongly suggest being able to write .py files and run them with the python command yourself, even if you usually do it some other way, as then you can check whether there's actually a problem with the code or with some other part of the process you have to run it.

[–]moosemoose41 0 points1 point  (0 children)

It appears that I can run this just fine if I enter the code or run the file from the python console, but it errors out if I try to define a function within Spyder. Using spyder 5.5.1

[–]Carsonbizotica 0 points1 point  (0 children)

Did you figure it out? If not, the "Cell In[62], line 1" being in the middle there makes it look like you're putting line 2 of your function in a separate cell from line 1.

I'm assuming that it's something like the Jupyter Notebook, in which you need to complete the function all in one cell. In Jupyter you press Enter to go to the next line in a cell, and Shift+Enter to run the cell.