gpt4 book ai didi

python - 导入程序 IDLE 时出错

转载 作者:行者123 更新时间:2023-12-01 05:56:26 25 4
gpt4 key购买 nike

我是 Python 新手,但我进展得很好,但我似乎无法将保存程序导入 IDLE。有人可以在这方面帮助我吗?无论程序多么简单,这都是错误之一:

>>> import dinner

Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
import dinner
File "C:\Python25\dinner.py", line 1
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
^
SyntaxError: invalid syntax

最佳答案

如果您的 dinner.py 程序实际上以该行启动,则会出现此错误

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32

但这不是一行有效的 Python 代码,而是解释器在启动时给出的消息。例如,我的说

~/coding$ python
Python 2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

然后我开始输入诸如 print 2+2 等内容。您可以在 IDLE 中打开 dinner.py 并删除任何看起来像欢迎的部分开头的消息。

顺便说一句,我看到您正在使用 Python 2.5.4。现在已经很老了,并且从那时起添加了很多巧妙的东西。我建议改用 2.7.3。

关于python - 导入程序 IDLE 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12395790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com