我创建了一个.py文件并将其保存在我桌面上的“Python”文件夹中。现在,我想执行名为“ use.py”的特定文件。
如何使用 LXTerminal 执行文件?
您在这里有多种选择(选择您最喜欢的一种):
使文件本身可执行。
在文件的第一行,确保“shebang”在那里:
#!/usr/bin/env python
Run Code Online (Sandbox Code Playgroud)
这是 shell 所必需的,以便它知道如何运行该文件。
标记文件系统上的可执行文件:
chmod +x thefile.py
Run Code Online (Sandbox Code Playgroud)像任何其他可执行文件一样运行它:
./thefile.py
Run Code Online (Sandbox Code Playgroud)
或者
/full/path/to/thefile.py
Run Code Online (Sandbox Code Playgroud)直接在 Python 解释器中运行文件:
python thefile.py
Run Code Online (Sandbox Code Playgroud)
这样做的缺点是每个想要运行该文件的人都应该知道如何调用它。使用第一个选项,您可以在文件本身中找到它,并且您可以在不知道的情况下运行该文件。
| 归档时间: |
|
| 查看次数: |
6498 次 |
| 最近记录: |