当前位置: 首页>>代码示例>>Python>>正文


Python Book.delete_entry方法代码示例

本文整理汇总了Python中book.Book.delete_entry方法的典型用法代码示例。如果您正苦于以下问题:Python Book.delete_entry方法的具体用法?Python Book.delete_entry怎么用?Python Book.delete_entry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在book.Book的用法示例。


在下文中一共展示了Book.delete_entry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from book import Book [as 别名]
# 或者: from book.Book import delete_entry [as 别名]
def main():
    while True:
        print "\nSelect an action, then hit enter:\
               \n1-Creat a new book\
               \n2-Open a book\
               \n9-quit"

        inp = raw_input().strip()
        if not inp.isdigit():
            print "Invalid input!"
            continue
        choice = int(inp)
        if choice == 1 or choice == 2:
            b = None
            if choice == 1:
                b = Book()
            elif choice == 2:
                try:
                    path = raw_input("book path:").strip()
                    b = Book(path)
                except IOError:
                    sys.stderr.write("\nFile '%s' cannot be read!\n" % path)
                    continue
            while True:
                print "\nSelect an action for the book: \
                    \n1-add entry\
                    \n2-print entry\
                    \n3-save as\
                    \n4-sort by(fname, lname or zip_code)\
                    \n5-delete an entry(by index based on print)\
                    \n6-edit an entry\
                    \n9-return to up level"

                inp2 = raw_input().strip()
                if not inp2.isdigit():
                    print "Invalid input!"
                    continue
                choice2 = int(inp2)
                if choice2 == 1:
                    fname = raw_input("firstname:").strip()
                    lname = raw_input("lastname:").strip()
                    b.add_entry(Entry(fname, lname))
                elif choice2 == 2:
                    b.show_entry()
                elif choice2 == 3:
                    path = raw_input("file name:").strip()
                    b.save_as(path)
                elif choice2 == 4:
                    attr = raw_input(("input '%s', '%s' or '%s':") % (FNAME, LNAME, ZIP_CODE)).strip()
                    b.sort(attr)
                elif choice2 == 5:
                    l = len(b)
                    if l == 0:
                        print "Nothing left!"
                        continue
                    index = raw_input("input 0-" + str(l - 1) + ":").strip()
                    if not index.isdigit() or int(index) < 0 or int(index) > l - 1:
                        print "Invalid input!"
                        continue
                    b.delete_entry(int(index))
                elif choice2 == 6:
                    l = len(b)
                    if l == 0:
                        print "Nothing to edit!"
                        continue
                    index = raw_input("select an entry to edit (input 0-" + str(l - 1) + "):").strip()
                    if not index.isdigit() or int(index) < 0 or int(index) > l - 1:
                        print "Invalid input!"
                        continue
                    attr = raw_input(
                        ("select an attribute to edit '%s', '%s', '%s', '%s', '%s', '%s', '%s' or '%s':")
                        % (FNAME, LNAME, ADDR, CITY, STATE, ZIP_CODE, PHONE_NUM, EMAIL)
                    ).strip()
                    value = raw_input("input an value for %s:" % attr).strip()
                    if utility.validate(attr, value):
                        b.edit_entry(int(index), attr, value)
                    else:
                        print ("\nInvalid value for %s!") % attr
                elif choice2 == 9:
                    break
                else:
                    print "Unimplemented!"
        elif choice == 9:
            break
        else:
            print "Unimplemented!"
开发者ID:SeMorgana,项目名称:address-book,代码行数:88,代码来源:cli.py


注:本文中的book.Book.delete_entry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。