Running Run Module on Python IDLE results in invalid synctax

Asked 2 years ago, Updated 2 years ago, 87 views

This is a rudimentary question.When you first type Hello World! and run the module, it becomes invalid syntax, and then the middle 7 of 3.7.3 is painted red.How can I solve this?I can't move on.

Enter a description of the image here

Supplemental
This is the Windows python IDLE.
When I opened IDLE and entered the screen, there was no Run in the top bar, so I opened the saved one and said Run→Run Module and got an error.

python python-idle

2022-09-29 22:50

2 Answers

The screen is too simple to understand, but you need to be aware that IDLE has two types: Shell Window and Editor Window.

Cause of Error

  • After starting IDLE, >>>> prompts you to enter the shell listening state.
  • On this screen, print("Hello, World!") Enter to display the results and wait for input again.
  • Now save the file with the appropriate name in File->Save As
  • When you open a saved file in Notepad or a text editor, the contents displayed on the IDLE screen are saved.
  • The saved file contains extra characters such as Python version information and prompts, so if you continue, you will get Syntax Error.

Correct Steps

  • If you are writing a script, open the editor window in File->New File after starting IDLE (whites characters are blank).
  • Python description required here, e.g. print("Hello, World!") Enter to save the file.
  • Run the Run Module from here and the script should run successfully on the shell window side.

Enter a description of the image here


2022-09-29 22:50

It's true that the same thing happens here

 print ("Hello world")

I don't think it's a special operation to type only

when running 64 bits of Python 3.7.4 in Windows 10 In Shell, even if there is no problem with the operation of the enter key, the py created by Save on the File menu will generate syntax errors when you run the Run Module from the Run menu.
Full-width spaces not found,
It seems to be different from the error display when I tried Shell.
Excuse me, but may I ask you how it was resolved?


2022-09-29 22:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.