简体   繁体   English

当我不保存代码时,Python 中的 IDLE 编辑器将不会运行我的代码

[英]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.

相关问题 我无法在闲置或pycharm或任何平台中运行python代码 - I cant run my python code in idle or pycharm or any platform Python IDLE 如何从编辑器到 shell - Python IDLE how do I get from editor to shell 我无法让我的代码通过 IDE 运行,但我可以通过 IDLE (Python 3) - I can't get my code to run through and IDE but I can through IDLE (Python 3) 为什么我的代码在IDLE中工作,但在保存文件并双击文件后却无法工作 - Why does my code work in IDLE but not when I save the file and double click the file 为什么我的代码可以在IDLE中工作,但在保存文件并双击文件后却不能工作? - why does my code works in IDLE but not when I save the file and double click the file? 如何在 Sublime Text 中创建构建系统以在 IDLE shell 中运行我的 python 代码? - How can I create a build system in Sublime Text to run my python code in an IDLE shell? 在sublime text3和IDLE中运行我的Python代码,但结果不一样 - Run my Python code in sublime text3 and in IDLE,But the results are not the same python IDLE不会运行我以前保存和重新打开的代码 - python IDLE won't run my previously saved and reopened code 在 IDLE 上导入文件(python 代码编辑器) - Importing FIles on IDLE (python code editor) 由于在 IDLE 中运行我的 Python 代码,我一直得到“无”的结果是谁? - Who do I keep getting "None" as a result of running my Python code in IDLE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM