I am currently able to run files through my python script via a .bat file. The contents of this batch file is simply:
我目前能够通过我的python脚本通过.bat文件运行文件。这个批处理文件的内容很简单:
C:\Python26\python.exe mypythonfile.py %1
pause
I can drag and drop various files onto the .bat file and the python script will execute, using the dropped file as the argument...using sys.argv
我可以将各种文件拖放到.bat文件中,并使用删除的文件作为参数执行python脚本...使用sys.argv
This is fine for windows. But what I want to do now, is do the equivalent in Linux.
这对窗户来说很好。但我现在要做的是在Linux中做同样的事情。
Any help would be greatly appreciated.
任何帮助将不胜感激。
2 个解决方案
#1
1
the equivalent of your script on a bourne compatible shell
(like bash
, dash
, zsh
and most other shells you ever find on linux) would be:
相当于bourne兼容shell上的脚本(比如bash,dash,zsh和你在linux上找到的大多数其他shell)将是:
#!/bin/sh
python /path/to/my/pythonfile.py $1
read
in practice this is not really needed, as for drag-n-drop you would create an application "shortcut" on your desktop that simply contains python /path/to/my/pythonfile.py $1
as the application string. and be done with it.
在实践中,这并不是真的需要,因为对于拖放操作,您将在桌面上创建一个应用程序“快捷方式”,它只包含python /path/to/my/pythonfile.py $ 1作为应用程序字符串。并完成它。
the really clean solution would even add the shebang #!/usr/bin/python
to the top of your .py-file and make it executable - so you can run it directly as
真正干净的解决方案甚至会将shebang#!/ usr / bin / python添加到.py文件的顶部并使其可执行 - 所以你可以直接运行它
/path/to/my/pythonfile.py $1
integrating the script with your GUI (icon, where you can drop things at), is depending on the actual desktop environment you use.
将脚本与GUI(图标,您可以在哪里放置)集成,取决于您使用的实际桌面环境。
xfce4
create a new launcher (e.g. right-click on a panel, "add new element", choose Starter; then right click on the newly created Starter-Icon, click on "add new object", give it a name and in the cmdline-field add
创建一个新的启动器(例如右键单击面板,“添加新元素”,选择Starter;然后右键单击新创建的Starter-Icon,单击“添加新对象”,为其命名并在cmdline中 - 字段添加
/full/path/to/my/script.sh %U
the %U
will be replaced with whatever you drop on the icon.
%U将替换为您放在图标上的任何内容。
#2
0
You don't need a separate script if you start your python file with something like:
如果您使用以下内容启动python文件,则不需要单独的脚本:
#!/usr/bin/python
Then you can simply drag & drop things on the python script itself.
然后你可以简单地拖放python脚本本身的东西。
#1
1
the equivalent of your script on a bourne compatible shell
(like bash
, dash
, zsh
and most other shells you ever find on linux) would be:
相当于bourne兼容shell上的脚本(比如bash,dash,zsh和你在linux上找到的大多数其他shell)将是:
#!/bin/sh
python /path/to/my/pythonfile.py $1
read
in practice this is not really needed, as for drag-n-drop you would create an application "shortcut" on your desktop that simply contains python /path/to/my/pythonfile.py $1
as the application string. and be done with it.
在实践中,这并不是真的需要,因为对于拖放操作,您将在桌面上创建一个应用程序“快捷方式”,它只包含python /path/to/my/pythonfile.py $ 1作为应用程序字符串。并完成它。
the really clean solution would even add the shebang #!/usr/bin/python
to the top of your .py-file and make it executable - so you can run it directly as
真正干净的解决方案甚至会将shebang#!/ usr / bin / python添加到.py文件的顶部并使其可执行 - 所以你可以直接运行它
/path/to/my/pythonfile.py $1
integrating the script with your GUI (icon, where you can drop things at), is depending on the actual desktop environment you use.
将脚本与GUI(图标,您可以在哪里放置)集成,取决于您使用的实际桌面环境。
xfce4
create a new launcher (e.g. right-click on a panel, "add new element", choose Starter; then right click on the newly created Starter-Icon, click on "add new object", give it a name and in the cmdline-field add
创建一个新的启动器(例如右键单击面板,“添加新元素”,选择Starter;然后右键单击新创建的Starter-Icon,单击“添加新对象”,为其命名并在cmdline中 - 字段添加
/full/path/to/my/script.sh %U
the %U
will be replaced with whatever you drop on the icon.
%U将替换为您放在图标上的任何内容。
#2
0
You don't need a separate script if you start your python file with something like:
如果您使用以下内容启动python文件,则不需要单独的脚本:
#!/usr/bin/python
Then you can simply drag & drop things on the python script itself.
然后你可以简单地拖放python脚本本身的东西。