How to execute python file in linux

前端 未结 7 666
长情又很酷
长情又很酷 2020-12-08 14:27

I am using linux mint, and to run a python file I have to type in the terminal: python [file path], so is there way to make the file executable, and make it run

7条回答
  •  一向
    一向 (楼主)
    2020-12-08 14:53

    1.save your file name as hey.py with the below given hello world script

    #! /usr/bin/python
    print('Hello, world!')
    

    2.open the terminal in that directory

    $ python hey.py
    

    or if you are using python3 then

    $ python3 hey.py
    

提交回复
热议问题