我的程序需要一个环境变量作为其参数之一:
myprogram --folder=$HOME/.special
Run Code Online (Sandbox Code Playgroud)
但是,如果我将它放入.desktop文件的exec行,它不起作用:
Exec=myprogram --folder=$HOME/.special
Run Code Online (Sandbox Code Playgroud)
$ HOME似乎无所事事.
我觉得我想在Python中使用"Everything"关键字,它具有以下属性:
x in Everything无论x如何,对表单的任何布尔测试都将始终返回True.for x in Everything会引发异常我的动机是我希望有一个可选的白名单并测试其中的成员资格,但我希望默认只是通过.
所以而不是写:
def check_allowed(x, whitelist=None):
if whitelist is None or x in whitelist:
print("x is ok")
else:
print("x is not ok")
Run Code Online (Sandbox Code Playgroud)
我想这样做:
def check_allowed(x, whitelist=Everything):
if x in whitelist:
print("x is ok")
else:
print("x is not ok")
Run Code Online (Sandbox Code Playgroud)
对我来说,第二个版本似乎更简单,更Pythonic,但我不知道如何实现这样的事情.
或者,我会接受为什么第一个版本更好的解释,这是我不应该想要的.