运行python程序总是要打开终端,cd
到目录,输入python $file
,真的很麻烦,找了一下资料,发现如下:
- 在
/home/ydf/.local/share/nautilus/scripts/
文件夹下新建run_on_python
和run_on_python_helper
文件,内容如下:
# run_on_python
gnome-terminal -e "expect /home/ydf/.local/share/nautilus/scripts/run_on_python_helper $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
# run_on_python_helper
#!/usr/bin/expect -f
# Get a Bash shell
spawn -noecho bash
# Wait for a prompt
expect "$ "
set file [lindex $argv 0]
# Type something
send "python $file\n"
# Hand over control to the user
interact
exit
给
run_on_python
文件增加可执行权限:右键=>Properties=>Permissions=>Allow executing as files as program。建立测试文件:
lalala.py
,内容如下:
import time
for i in range(10):
print 'klalala'
time.sleep(1)
- 右键
lalala.py
=>Scripts=>run_on_python,即可看到效果了。