我想实现下一个行为:
python script.py
> my_arg is None
python script.py --my-arg
> my_arg is "default"
python script.py --my-arg some_value
> my_arg is "some_value"
Run Code Online (Sandbox Code Playgroud)
如何为 Argparser 配置此参数?
到目前为止我尝试过的:
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--my-argument', nargs='?', default='default')
args = parser.parse_args()
print(args.my_argument)
Run Code Online (Sandbox Code Playgroud)
但因为test.py
我有default
我想将浏览器限制在一组URL中.我正在使用:
chrome.webNavigation.onBeforeNavigate.addListener(functon(details){
if (notAllowed(details.url)) {
// Do something to stop navigation
}
});
Run Code Online (Sandbox Code Playgroud)
我知道我可以取消chrome.webRequest.onBeforeRequest
.但是,我不想阻止请求,例如XHR或其他任何请求.我希望此过滤器仅适用于导航.
对于用户来说,应该看起来,链接(例如<a href="http://...">foo</a>
)点击事件已经停止.
我有带有子网的表
cidr | ip
Run Code Online (Sandbox Code Playgroud)
我想通过所属IP列表选择子网。在postgres中,我可以这样进行:
select
ips.ip, net.uid, net.cidr
from
TBL_SID_SUBNETWORK net,
(select unnest(ARRAY[1,2,3]) ip) ips
where
cast (((2^net.cidr) - 1) as bigint)<<(32 - net.cidr) & ips.ip = net.ipaddress
Run Code Online (Sandbox Code Playgroud)
在postgres中,我可以传递数组并将其用作表。
select ips.ip from
(select unnest(ARRAY[1,2,3]) ip) ips
|ip|
1
2
3
Run Code Online (Sandbox Code Playgroud)
可以在Oracle中做类似的事情吗?在一个查询中?我不想创建,填充和删除其他表,因为我间接使用DB,并且事务由应用程序配置管理。
我知道Oracle的TABLE(collection)
功能与我想要的功能完全相同。但是我无法将集合传递到该查询中,因为我应该在之前声明并填充集合,因此,这与创建临时表相同。
如果我不知道包装函数的名称,是否可以使用 python 装饰器来标记方法并获取它以供以后使用?
这是示例,我不知道 method_with_custom_name 的名称:
@run_this_method
def method_with_custom_name(my_arg):
return "The args is: " + my_arg
def _init_and_run():
# Here, I want to get and call method_with_custom_name
# but I don't know it's name,
# so the next line isn't valid.
return run_this_method()(my_arg_value)
def run_this_method(m):
def w(my_arg):
_do_some_magic(my_arg, m)
return w
def _do_some_magic(callback_arg, callback):
if some_checks():
callback(callback_arg)
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能获得包含的方法列表@run_this_method