本文整理汇总了Python中Filter.Filter.is_valid_condition方法的典型用法代码示例。如果您正苦于以下问题:Python Filter.is_valid_condition方法的具体用法?Python Filter.is_valid_condition怎么用?Python Filter.is_valid_condition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filter.Filter
的用法示例。
在下文中一共展示了Filter.is_valid_condition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_entries
# 需要导入模块: from Filter import Filter [as 别名]
# 或者: from Filter.Filter import is_valid_condition [as 别名]
def filter_entries(filter_str=''):
"""
Enter and handle filter mode.
Prompts for filter conditions to filter the list of entries and commands to handle entries in bulk.
:param filter_str: An optional initial filter condition string.
:return: None.
"""
f = Filter(list(diary.entries)) # Pass a copy of diary.entries to prevent skipping when using `remove`
if filter_str:
handle_add_filter_condition(f, filter_str)
else:
display_filters(f)
while True:
cmd = get_input('{} (filter mode)> '.format(PROMPT),
condition=lambda x: x != '', # Do not accept blank string
err_msg='') # No error message if blank string is entered
if f.is_valid_condition(cmd):
handle_add_filter_condition(f, cmd)
elif cmd in ['quit', 'q']:
break
elif cmd in ['clear', 'c']:
f.reset()
display_filters(f)
elif cmd in ['l', 'list']:
display_filters(f)
else: # Otherwise a diary command has been entered
cmd, f_args = process_input(cmd) # Separate command and arguments
if cmd in [remove, edit, priority, extend]: # These are the only commands available in filter mode
for obj in f.objects:
new_args = '{} {}'.format(obj.uid, f_args) # Insert UID of each entry one at a time
cmd(new_args)
break