Python Nautilus脚本 [英] Python Nautilus script

查看:70
本文介绍了Python Nautilus脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在为Nautilus编写一个python脚本。

获取在Nautilus右侧窗格中选择的文件列表,你使用

$ NAUTILUS_SCRIPT_SELECTED_FILE_PATHS环境变量,这是脚本通常可用的
。实际上,它适用于bash脚本

但不适用于python脚本


import os

files = os.environ ['' NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'']。splitlines()


给出一个:


文件"< stdin>",第1行,在< ;模块>

文件" /usr/lib/python2.5/UserDict.py" ;,第22行,在__getitem__

引发KeyError(键)

KeyError:''NAUTILUS_SCRIPT_SELECTED_FILE_PATHS''

Fredrik Lundh向我解释说,所有环境变量都不是可以从应用程序的子进程访问的.b $ b。 />

所以我的问题是如何在python

脚本中获取Nautilus选择的文件?


谢谢,

米歇尔

-

Michel Leunen
http://linux.leunen.com

推荐答案

NAUTILUS_SCRIPT_SELECTED_F ILE_PATHS环境变量是脚本通常可用的
。实际上,它适用于bash脚本

但不适用于python脚本


import os

files = os.environ ['' NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'']。splitlines()


给出一个:


文件"< stdin>",第1行,在< ;模块>

文件" /usr/lib/python2.5/UserDict.py" ;,第22行,在__getitem__

引发KeyError(键)

KeyError:''NAUTILUS_SCRIPT_SELECTED_FILE_PATHS''

Fredrik Lundh向我解释说,所有环境变量都不是可以从应用程序的子进程访问的.b $ b。 />

所以我的问题是如何在python

脚本中获取Nautilus选择的文件?


谢谢,

米歇尔

-

Michel Leunen
http://linux.leunen.com
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS environment variable which is
normally available to the script. Actually, it works with bash scripts
but not with python scripts

import os
files = os.environ[''NAUTILUS_SCRIPT_SELECTED_FILE_PATHS''].splitlines()

gives a:

File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: ''NAUTILUS_SCRIPT_SELECTED_FILE_PATHS''

Fredrik Lundh explained me that all environment variables are not
accessible from subprocesses of an application.

So my question is how can I get the Nautilus selected files in a python
script?

Thanks,
Michel
--
Michel Leunen
http://linux.leunen.com


Michel Leunen schrieb:
Michel Leunen schrieb:




我正在为Nautilus编写一个python脚本。

获取所选文件列表在Nautilus右侧窗格中,您使用

Hi,

I''m trying to write a python script for Nautilus.
To get the list of files selected in the Nautilus right pane, you use
the


NAUTILUS_SCRIPT_SELECTED_FILE_PATHS环境变量,这是脚本通常可用的
。实际上,它适用于bash脚本

但不适用于python脚本


import os

files = os.environ ['' NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'']。splitlines()


给出一个:


文件"< stdin>",第1行,在< ;模块>

文件" /usr/lib/python2.5/UserDict.py" ;,第22行,在__getitem__

引发KeyError(键)

KeyError:''NAUTILUS_SCRIPT_SELECTED_FILE_PATHS''

Fredrik Lundh向我解释说,所有环境变量都不是可以从应用程序的子进程访问的.b $ b。 />

所以我的问题是如何在python

脚本中获取Nautilus选择的文件?
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS environment variable which is
normally available to the script. Actually, it works with bash scripts
but not with python scripts

import os
files = os.environ[''NAUTILUS_SCRIPT_SELECTED_FILE_PATHS''].splitlines()

gives a:

File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: ''NAUTILUS_SCRIPT_SELECTED_FILE_PATHS''

Fredrik Lundh explained me that all environment variables are not
accessible from subprocesses of an application.

So my question is how can I get the Nautilus selected files in a python
script?



shell脚本和
python脚本之间不应该有区别。环境变量是一个unix-process-thing,因此

管理它们的规则适用于* all *进程 - shell是一个

这些,有没什么特别的。


如果shell脚本获取变量,那么python脚本也会如此。


你确定shell获取值?或者只是默默地忽略了一个

缺失值,而python脚本不是吗?根据文档(我只用Google搜索变量名),变量似乎只设置为只有

如果是本地[1],无论这意味着什么。

https://help.ubuntu.com/community / NautilusScriptsHowto


Diez

There shouldn''t be a difference between a shell-script and a
python-script. Environment-variables are a unix-process-thing, and thus
the rules that govern them apply to *all* processes - the shell is one
of these, there is nothing special to it.

If the shell-script gets the variable, the python-script will as well.

Are you sure the shell gets the value? Or is it just silently ignoring a
missing value, and the python-script isn''t? According to the docs (I
only googled the variable-name), the variable seems only to be set "only
if local"[1], whatever that means.

https://help.ubuntu.com/community/NautilusScriptsHowto

Diez


这篇关于Python Nautilus脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆