我想在路径中添加一些python脚本.
我可以将bash脚本添加到路径中的文件夹中,然后从任何地方执行它们.当我使用python脚本时,我只能在同一目录中执行它们.
例如,如果我将test和test2.py放在我路径中的同一文件夹中.
这项工作:
Run Code Online (Sandbox Code Playgroud)sh test success hello world
这不是:
Run Code Online (Sandbox Code Playgroud)python test.2.py python: can't open file 'test2.py': [Errno 2] No such file or directory [Errno 2] No such file or directory
假设python源文件位于路径中的目录中,请执行以下操作:
#!/usr/bin/env pythonchmod +x test.2.pytest.2.py