Error in file and not being able to excute code in IDLE

Hi guys,

I’m new to Python and I’m having a problem (Maybe a silly one):

I can’t write code in IDLE (see images on right side) in a project I was working on, in that project I don’t have the >>> to write anything, when I open IDLE, I can write (see image on left side) but when I save and close the project and I open it again, I can’t do nothing.

Also I’m following a small course to learn and I’m following the steps, so I created a module (Calculator - see image on right bottom side) and I’m importing the module to other project but I can’t, I’m receiving a error message (see image right top side)
Could someone guide me please?

Below the images to explain myself better:

Regards,

Iván

When you use Python interactively, it starts by printing a header announcing its version, etc, and then prints a prompt >>>, as you have in the left-hand window.

None of that should be in programs that you write. Only the Python code itself should be in them.

1 Like

Hi Matthew,

Thanks for the reply, and regarding the error, can you help me?

Thanks

The top-right and bottom-right windows show the programs, but they contain stuff that shouldn’t be there, stuff that Python printed when used interactively, such as the header and prompt.

It looks like you just saved an interactive session to a file.

That won’t work.

If you want your program to import the Calculator modulem, for example, you’d write:

import Calculator

You wouldn’t write the prompt >>> because that’s not part of a program, it’s just, well, a prompt for you that Python prints when you’re using it interactively.

1 Like

Thanks for the help :call_me_hand:

Editing a saved interactive session requires a lot of deletion. The lower right should begin

def add(num1, num2):
    return num1 + num2

def sub(num1, num2):
    return num1 - num2
# etc

So I haven’t used IDLE much at all really. But it seems you have two types of windows, interactive/shell, and editor - file editing mode. The first for trying things, the second for saving into files you can import later. Think for coding you need a text editor, and some way of running the files you write.

I saw an IDE recently called Thonny which I would easily use for learning and writing - works well on Windows and probably Gnome environments - edit Linux works if you turn off Zenity dialogs in the Tools Options.

VSCode, Pycharm have autocomplete. Oh wow, Thonny does too…