I am currently able to run files through my python script via a .bat file. The contents of this batch file is simply:
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
This is fine for windows. But what I want to do now, is do the equivalent in Linux.
Any help would be greatly appreciated.
the equivalent of your script on a
bourne compatible shell
(likebash
,dash
,zsh
and most other shells you ever find on linux) would be: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.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 asintegrating the script with your GUI (icon, where you can drop things at), is depending on the actual desktop environment you use.
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
the
%U
will be replaced with whatever you drop on the icon.You don't need a separate script if you start your python file with something like:
Then you can simply drag & drop things on the python script itself.