【问题标题】:python IDLE won't run my previously saved and reopened codepython IDLE 不会运行我之前保存并重新打开的代码
【发布时间】:2011-10-14 05:05:42
【问题描述】:

我最近开始学习 python,当我关闭 IDLE 并保存我的工作时。 当我回到它打开空闲并打开我保存的工作并使用 f5 运行模块进行测试时,模块不会产生错误代码,甚至不会打印出我的简单打印命令。如果我用几个命令快速输入一个新项目,它工作得很好,这只是我以前保存的工作......

有人有什么想法吗?

我的操作系统是 Windows 7 家庭版,知道我以前安装过 3.2 和 2.6 可能会有所帮助

编辑:原来我的代码不会通过 python 在命令中运行,或者我的代码似乎很好,但会在这里发布:

import random
import time

Coin = 100
Health = 100
PCName = ()

def displayIntro():
    print "You wake, bound to the cell wall by shackles..."

【问题讨论】:

    标签: python


    【解决方案1】:

    执行这个模块不会做任何事情。您只需进行一些导入,定义一些全局变量并定义一个函数。如果你想看到打印的东西,你必须调用你的函数:

    import random
    import time
    
    Coin = 100
    Health = 100
    PCName = ()
    
    def displayIntro():
        print "You wake, bound to the cell wall by shackles..."
    
    displayIntro() # when the interpreter reaches this line, a warm welcome will be printed
    

    【讨论】:

    • 谢谢你。愚蠢的教程实际上并没有说明 displayIntro():
    【解决方案2】:

    您编写的代码是 Python 2,而不是 3。以下是您应该如何调用 print():

        print("You wake, bound to the cell wall by shackles...")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多