當前位置: 首頁>>代碼示例>>Python>>正文


Python Filter.is_valid_condition方法代碼示例

本文整理匯總了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
開發者ID:aaron-lucas,項目名稱:CMDiary,代碼行數:38,代碼來源:cmdiary.py


注:本文中的Filter.Filter.is_valid_condition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。