在Windows 7 64位上从IDLE运行Python脚本

use*_*080 6 python python-idle

我试图弄清楚如何在Windows 7上成功使用Python 2.7.1.
到目前为止,我不得不使用shell(IDLE)来创建脚本,然后从cmd提示符运行它们.我觉得这会减慢学习过程,我想知道是否有办法从IDLE运行它(我无法创建路径,所以每当我尝试打开或导入文件时我都会收到错误)或还是其他一些程序/文本编辑器?

任何帮助,将不胜感激!我可能只是做错了什么.

Mar*_*nen 19

  1. 运行IDLE.您将看到"Python Shell"窗口和>>>提示.
  2. 单击文件,新窗口.您将看到一个用于编辑脚本的"无标题"窗口.
  3. 在"无标题"窗口中输入您的脚本.
  4. 在"无标题"窗口中,选择"运行","运行模块"(或按F5)以运行脚本.
  5. 一个对话框"必须保存来源.确定要保存吗?" 出现.单击确定.
  6. 在"另存为"对话框中:
    a.浏览到目录以保存脚本.
    湾 输入文件名.
    C.单击保存.
  7. "Python Shell"窗口将显示脚本的输出.
  8. 编辑脚本并根据需要按F5重新运行脚本.

编辑

我通常不使用IDLE,并且没有立即看到为模块配置参数的方法,因此一个建议是切换IDE.由于您使用的是Windows 7,因此pywin32扩展包含PythonWin IDE,其运行命令有一个对话框,允许输入命令行参数.


May*_*erg 5

我认为您要记住以下功能:

execfile(...)

execfile(filename[, globals[, locals]])

Read and execute a Python script from a file.
The globals and locals are dictionaries, defaulting to the current
globals and locals.  If only globals is given, locals defaults to it.
Run Code Online (Sandbox Code Playgroud)

注意:

这仅适用于python 2.x,而python 3没有execfile(),而是请参阅python 3中execfile的替代方法是什么?