1

Im new to Python but Im getting on pretty well, however I cannot seem to import save programs into IDLE. Could someone assist me where that is concerned, please. This is one of the errors no matter how simple the program is:

>>> 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
4

1 回答 1

2

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等之类的内容。您可以dinner.py在 IDLE 中打开并删除任何一开始看起来像此欢迎消息的部分。

顺便说一句,我看到您使用的是 Python 2.5.4。这现在已经很老了,从那以后添加了很多整洁的东西。我建议改用 2.7.3。

于 2012-09-12T20:46:37.763 回答