从终端运行python程序

终端窗口运行.py程序 

  首先你要安装python,命令行输入 python 有python提示符 >>> 出现说明安装成功

  程序第一行应该是 #! python3  

#! python3
market_2nd={'ns':'green','ew':'red'} #ns南北向,ew东西向

def switchLights(stoplight):
    for key in stoplight.keys():
        if stoplight[key]=='green':
            stoplight[key]='yellow'
        elif stoplight[key]=='yellow':
            stoplight[key]='red'
        elif stoplight[key]=='red':
            stoplight[key]='green'
    assert 'red' in stoplight.values(),'交通灯都不是红色的'+str(stoplight)
switchLights(market_2nd)
print(market_2nd)
switchLights(market_2nd)
print(market_2nd)
switchLights(market_2nd)
print(market_2nd)

  

  输入命令格式

  这里的地址是完整的地址,

python D:\desktop\forTest.py #文件的完整目录

  结果:

  这里的-O禁止断言

命令行里的 python shell  环境

  打开cmd后直接输入 python 会进入 python 的 shell 环境,这里可以可以输入命令,还有就是 shell 里会有提示符 >>> 

  如 print('I love you')   

  运行结果:

 

   使用 exit() 退出 python 的 shell 环境

  

  File "<stdin>", line 1 错误:

  在shell 里面输入 python +程序名字 ,会出现这个错误,应该在终端下运行(见上)

猜你喜欢

转载自www.cnblogs.com/Gaoqiking/p/10484211.html