Ubuntu14.04增加右键菜单=>“run_on_python”

运行python程序总是要打开终端,cd到目录,输入python $file,真的很麻烦,找了一下资料,发现如下:

  • /home/ydf/.local/share/nautilus/scripts/文件夹下新建run_on_pythonrun_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,即可看到效果了。

你可能感兴趣的:(python,ubuntu)