一:怎样运行python程序

运行python程序有三种方法:

1,在命令行运行python代码:C:/python27>python hello.py   【注:如果没有把PATH环境变量设置为包含这一路径,要确保输入到了python 的完整路径,并且如果py程序不在同一文件夹下,需要声明绝对路径】

      eg:C:\Users\张朋\AppData\Local\Programs\Python\Python36-32 > python36  C:\hello.py [Enter]

2,将py程序看作一个模块,进行模块的调用即可:

      eg:   C:\Users\张朋\AppData\Local\Programs\Python\Python36-32>python  [Enter]

    >>>import hello  [Enter]

3,使用exec运行模块文件:

     eg:    C:\Users\张朋\AppData\Local\Programs\Python\Python36-32>python  [Enter]

      >>> exec(open('hello.py').read())  [Enter]

posted on 2018-04-08 22:05  爱笑的张飞  阅读(471)  评论(0编辑  收藏  举报

导航