[英]The IDLE editor in Python will not run my code when I do not save it
I have written code in a New file window in IDLE.我在 IDLE 的新文件窗口中编写了代码。
When I run the code there is no output.当我运行代码时,没有输出。 Instead a dialog box appears showing a window accessing Python Folder 37-32.而是出现一个对话框,显示一个访问 Python 文件夹 37-32 的窗口。
When i closed the dialog box and the file I tried to create a new simple code below but I when I ran the code I got the same Dialog box.当我关闭对话框和文件时,我试图在下面创建一个新的简单代码,但是当我运行代码时,我得到了相同的对话框。
What is wrong?怎么了?
sum = 2+3 print(sum)
I have attached a screenshot showing the code and the dialog box that appears when the Module is run我附上了一个屏幕截图,显示了代码和模块运行时出现的对话框
Before you can execute your code, your first need to save the file.在执行代码之前,首先需要保存文件。 Thats the dialog box that popped up.这就是弹出的对话框。
You should have seen a popup box like below.您应该已经看到如下所示的弹出框。 Did you?你是否? Is is unclear?是不是不清楚?
Save Before Run or Check
? Source Must Be Saved
OK to Save?
[OK] [Cancel]
One reason to require saving is that exception tracebacks refer to the file and line of lines that lead to the exception.需要保存的一个原因是异常回溯引用导致异常的文件和行。
If you had saved, sum = 2+3 print(sum)
would be a SyntaxError.如果您已保存, sum = 2+3 print(sum)
将是 SyntaxError。
You can run single statements in Shell without saving.您可以在不保存的情况下在 Shell 中运行单个语句。
The RESTART lines says that the shell re-initialized the environment for executing your code. RESTART 行表示 shell 重新初始化了执行代码的环境。
You should normally not save your code buried in the installation Scripts directory.通常不应将代码保存在安装 Scripts 目录中。 Better to make a directory in your user directory, for instance, C:/Users/yourname/py/.最好在您的用户目录中创建一个目录,例如 C:/Users/yourname/py/。
Yes, one should usually open a new question for unrelated questions.是的,通常应该为不相关的问题打开一个新问题。 But without access to your machine, it is hard to know what happened with 'new'.但是如果无法访问您的机器,就很难知道“new”发生了什么。 It may be that IDLE could create a file under .../appdate/.../Scripts/
, but your code cannot.可能 IDLE 可以在.../appdate/.../Scripts/
下创建文件,但您的代码不能。 If the open call did not raise and exception, it was likely created somewhere.如果 open 调用没有引发和异常,它很可能是在某处创建的。 Until you are more experienced, better to use absolute paths, such as C:/Users/yourname/py/new.txt
.在您更有经验之前,最好使用绝对路径,例如C:/Users/yourname/py/new.txt
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.