shell脚本:通过shell脚本编译并执行python

时间:2017-09-10 23:16:56

标签: python linux shell

我知道如何编写python,但我不知道Unix,所以如何创建两个.sh文件来编译和执行我的python程序。例如,我的程序名为hello.py,我有两个名为compile.sh和execute.sh的文件,我想调用compile.sh然后编译hello.py,然后调用execute.sh然后执行hello.py 。谢谢!

1 个答案:

答案 0 :(得分:0)

除了编写Shell脚本(.sh文件)之外,您只需打开一个终端并从那里开始执行操作,请参阅http://www.dummies.com/computers/macs/mac-operating-systems/how-to-use-basic-unix-commands-to-work-in-terminal-on-your-mac/ - 无论您执行什么操作,都会像在Shell脚本中一样执行。 打开终端,只需输入

即可
python my_script.py

你触发python首先将代码编译为* .pyc文件,然后执行它。无需特殊步骤!无论您在终端中输入什么内容,您还可以将其另存为shell脚本并在以后运行。 Shell脚本在许多网站上教授,如https://www.shellscript.sh/和其他网站,谷歌是你的朋友。

相关问题