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

发布于 2024-11-17 15:02:48 字数 209 浏览 3 评论 0原文

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

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

I'm trying to figure out how to successfully use Python 2.7.1 on windows 7.
So far, I'm having to use the shell (IDLE) to create scripts and then run them from the cmd prompt. I feel this is slowing down the learning process and I was wondering if there was a way to run it from IDLE (I'm not able to create a pathway, so whenever i try to open or import a file i get an error) or some other program/text editor perhaps?

Any help would be appreciated! I'm probably just doing something wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你丑哭了我 2024-11-24 15:02:48
  1. 运行空闲。您将看到“Python Shell”窗口和 >>> 提示符。
  2. 单击“文件”、“新窗口”。您将看到一个“无标题”窗口,用于编辑脚本。
  3. 在“无标题”窗口中输入您的脚本。
  4. 在“无标题”窗口中,选择“运行”、“运行模块”(或按 F5)来运行脚本。
  5. 对话框“必须保存源。确定保存吗?”出现。单击“确定”。
  6. 在“另存为”对话框中:
    一个。浏览到保存脚本的目录。
    b.输入文件名。
    c.单击“保存”。
  7. “Python Shell”窗口将显示脚本的输出。
  8. 编辑脚本并根据需要按 F5 重新运行脚本。

编辑

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

  1. Run IDLE. You will be presented with the "Python Shell" window and a >>> prompt.
  2. Click File, New Window. You will be presented with an "Untitled" window for editing a script.
  3. Enter your script in the "Untitled" window.
  4. In the "Untitled" window, select Run, Run Module (or press F5) to run your script.
  5. A dialog "Source Must Be Saved. OK to Save?" appears. Click OK.
  6. In the Save As dialog:
    a. Browse to a directory to save your script.
    b. Enter a filename.
    c. Click Save.
  7. The "Python Shell" window will display the output of your script.
  8. Edit script and press F5 as needed to re-run your script.

Edit

I don't normally use IDLE, and didn't immediately see a way to configure parameters to the module, so one suggestion is to switch IDEs. Since you are using Windows 7, the pywin32 extensions contains the PythonWin IDE and its Run command has a dialog to allow command line parameters to be entered.

幻想少年梦 2024-11-24 15:02:48

我认为您想到了以下函数:

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.

注意:

这仅适用于 python 2.x,python 3 没有 execfile(),而是参见 Python 3 中 execfile 的替代品是什么?

I think you have in mind the following function:

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.

Note:

This only applies to python 2.x, python 3 does not have execfile(), instead see What is an alternative to execfile in Python 3?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文