Execute Python script file from Mac terminal command line

It is mainly divided into the following four steps:

  • First, add the first line in the python file#!/usr/bin/env python
#!/usr/bin/env python
print('hello, world!')
  • cd into the directory of the python file in the terminal
  • Add permissions: $ chmod 777 filename.py
  • Execute the script: ./filename.py

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325569085&siteId=291194637