Command Promts (>>>) Disappearing in IDLE

Hi everyone,

I am beginnging my first programming class in Python and am having issues with my program in IDLE.

The three carrot prompts (>>>) keeps disappearing on me in IDLE in both the interactive shell environment and script file window. See my screenshot attached.

It was working fine for me last week. But i started to write my profram and when i pressed enrter to the next line, the carrots disappeared and i just saw a blinking space bar so i could not write any executable code.

Has anyone seen this issue before? How do I go about resolving this issue? It seems quite strange how it worked before and now it suddenly is not working.

Thanks!

1 Like

Why do you expect/want them in the file editor?

I am trying to write more code but it won’t execute. I am new to this program and it always seems to have the carrots when i press enter to write another line of code that executes. Do you know what causes the command promts to disappear?

There shouldn’t be any. You’d have to remove them in order to run the script and it would be super annoying.

In the interactive shell, the “disappearing” that you are seeing could be the result of using input in those lines float(intput(".... If that is the case, it it because input is waiting for you to input something. What you type then, before you hit Enter, is what comes out of the function input and goes as input to float.

I am having issues with Python in IDLE. I tried to run my code but keep getting an error saying “Invalid Decimal Literal”. I was having issues with the carrot command promts (>>>) disppearing so not sure if this is related to that issue ? Any ideas? See my screenshot for support.

Yeah that’s not valid Python. Don’t dump arbitrary text into a Python script. Only valid Python code.

I was including detailed comments cause my teacher said she would dock points for it. So what is the reason for the Invalid Decimal Literal error ?

There are two kinds of windows in IDLE.

The ones that say “IDLE Shell” in the title bar are interpreter prompt windows. These will show a banner at the top that looks like:

Python 3.11.2 (main, Apr  5 2023, 03:08:14) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.

automatically when you open them, and give you a >>> prompt (the word you’re looking for is caret; but that’s still wrong, because it means the ^ symbol) where you can type individual lines of code to run a line at a time.

(For you, the banner looks a bit different, because you have a different version of Python, created using a different compiler, for a different operating system.)

The ones that have a file name (ending in .py) in the title bar are code editing windows. In these, you type complete Python programs, and save them as Python source code files. Then Python can run the entire program all at once. (This means, for example, that you can call input and not have to provide the input immediately; you can write the next line of the program directly underneath, and it isn’t used as the input.)

When you type your source code, you should not copy and paste from an interpreter prompt window into the code editing window. That’s because most of what you see in the interpreter prompt window is not actual code, but instead just guideline text to help you understand what’s going on. The >>> prompts (and ... continuations) are not part of the Python syntax; they’re just something the interpreter prompt shows you in order to explain that it’s waiting for you to type more code. The message at the top isn’t Python code; it’s just… a message, to tell you what version of Python you’re using and suggest some other special things you can do in the interpreter.

When you type the source code, you need to think and plan out in advance what will happen as the code runs, step by step. You don’t get to see it happening step by step, because the point is to make something that doesn’t have to wait for you to type in the code for the next step.

2 Likes

Think carefully about what would happen if you typed Python 3.12.2 at the interpreter prompt and pressed enter. If you aren’t sure, try it. If you’re still confused, here’s another hint: what does 3.12 mean in Python code? Does it make sense to put .2 after that?

@kknechtel It complains at the 6, though.

I was including detailed comments cause my teacher said she would dock
points for it.

And that’s a good thing. Keep doing it. This is not what’s causing the
error.

So what is the reason for the Invalid Decimal Literal error ?

The eror is highlighted in your screenshot (the red cursor directly
above the error message-in-a-box).

This is because you have pasted the Python IDLE preambl welcome message
into a Python programme. That’s not code, just a greeting and
information message from the interactive prompt. Leave it out.

As Karl has explained, you get this when you start Python interactively.
Example:

 CSS[~/hg/css(hg:default)]fleet2*> python3
 Python 3.9.6 (default, Nov 10 2023, 13:38:27)
 [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
 Type "help", "copyright", "credits" or "license" for more 
 information.
 >>>

That’s me typing “python3” to invoke Python as my prompt. All the guff
underneath up to the >>> prompt is not valid Python code, it’s just a
welcome message showing me some details about which Python I’m running.
Don’t include this stuff in your actual code.

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

That’s probably your editor syntax highlighting being a bit simple minded. That 6abdd9 is a revision control hash string. Your editor is probably trying to read it as a decimal value because it begins with a 6. It’s not a great error message, but the fix is to remove the whole preamble line from your code.

It’s not my code.

Sure. But it’s a transcript of someone entering Python at the IDLE prompt. However the window seems to be for pure Python code.

Karl described that there are 2 types of windows you’re dealing with: a code window for a Python programme, and an interactive window where you can run bits of Python code interactively.

The former is to just have Python in it and nothing else. So remove the Python 3.12.2…>>> stuff.

It appears to me that you’re pasting the transcript of an interactive session, complete with prompts etc etc into a pure Python code window. Do that, then remove the preamble string and all the >>> prompts, because they’re not part of the code, they’re the interactive mode giving prompts to whoever was doing this stuff.

Example: here’s the top of a Python file I’ve got sitting around:

#!/usr/bin/python
#
# Some Queue subclasses and ducktypes.
#       - Cameron Simpson <cs@cskk.id.au>
#

''' Queue-like items: iterable queues, channels, etc.
'''

from contextlib import contextmanager

See there’s no preamble? Just some comments (# ...), a leading docstring (''' ... ''') and an import statement. More code follows below, of course.

There are no preambles or >>> prompts.

1 Like

@cameron I’m not the OP.

And the OP is aware of the two types of windows. In their other topic they said:

Ah, I’ve been explaining to someone who already understands :frowning: Sorry.

(Merged the two threads on the same topic per participant request, since they are both essentially the same question and resulted in two parallel discussions)

There are two modes of writing python: in an interactive shell vs in a script.

In an interactive shell, python executes each command immediately after you finish writing it. The >>> is not part of python syntax, but is there to indicate you’re in interactive mode. A script, meanwhile, is a text file that contains all of your desired commands, you write them all ahead then run the script (see the “Run” tab on the menu bar), python will sequentially call all commands for you. There is no >>> in a script.

You are currently in scripting mode, but your script contains lots of stuff that only belong to an interactive shell, that’s why it doesn’t run. You can find somewhere in IDLE’s menu bar that lets you switch back and forth between two modes. As for your current program, it’s easiest to start all over again, as the mixing between two modes already made it a mess. You can use either mode for this program, just be aware of the difference as I explained above.

2 Likes

Thank you everyone for the support! I figured it was due to me coping unnessary welcome messages from the interactive shell to a script file and using >>> incorrectly in the script file. I have much to learn and am excited to learn the power of Python.

Cheers, Jake

1 Like