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


Python Contact.add方法代码示例

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


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

示例1: test_add_empty

# 需要导入模块: from contact import Contact [as 别名]
# 或者: from contact.Contact import add [as 别名]
 def test_add_empty(self):
     contact = Contact()
     added, phoneexist, comment = Contact.add(contact, self.c, ())
     self.assertFalse(added)
     self.assertFalse(phoneexist)
开发者ID:seniorivn,项目名称:python_contact_book,代码行数:7,代码来源:test.py

示例2: main

# 需要导入模块: from contact import Contact [as 别名]
# 或者: from contact.Contact import add [as 别名]
def main(args):
    sys.argv=args
    args= docopt(__doc__)
    contact = Contact()
    # contact.set_bday(args["--bday"])
    schema = Schema({
        '--contact_id': Or(None,And(Use(int),Use(contact.set_cid, error='id is not correct, it should be integer number'))),
        '--first_name': Or(None,Use(contact.set_fname, error='fname is not correct')),
        '--last_name': Or(None,Use(contact.set_lname, error='lname is not correct')),
        '--middle_name': Or(None,Use(contact.set_mname, error='mname is not correct')),
        '--phone': Or(None,Use(contact.set_phone, error='phone is not correct')),
        '--bday': Or(None,Use(contact.set_bday, error='birtday is not correct it should be one of the formats ' + str(contact.bday_types))),
        '--data': Or(None,Use(set_data, error='name was not correct')),
        '--reverse': Or(None,True,False),
        '--replace': Or(None,True,False),
        '--sort': Or(None,"fname","lname","mname","phone","bday", error="--sort should be one of the fname,lname,mname,phone,bday"),
        'add': Or(False,True),
        'del': Or(False, True),
        'find': Or(False,True),
        'list': Or(False,True),
        })
    try:
        schema.validate(args)
    except SchemaError as e:
        exit(e)
    try:
        connection = sqlite3.connect(database)
        c = connection.cursor()
        c.execute("create table contacts(id integer primary key autoincrement, fname text, lname text, mname text, phone text, bday text)")
        print("new database " + database + " was created")
    except sqlite3.Error as e:
        print("Existing database " + database)

    if args["add"]:
        added, phoneexist, comment = contact.add(contact, c, args)
        if added:
            print(comment+" " + str(contact.get_tuple()))
        else:
            print(comment)
    elif args["find"]:
        finded=contact.find(contact, c)
        if finded:
            print(tabulate(finded, headers=["Id","first name","last name","middle name","phone","birthday date"]))
        else:
            print("there is no any contact "+(("like:"+str(contact)) if str(contact) else ""))
    elif args["del"]:
        result, string=contact.delete(contact, c)
        print(string)
        if result:
            for r in result:
                print(r)
        else:
            sys.exit(-1)
    elif args["list"]:
        result = contact.lst(args, c)
        if result:
            print(tabulate(result, headers=["ID","first name","last name","middle name","phone","birthday date"]))
        else:
            print("there is empty database="+database)

    else:
        remind=contact.reminder(c)
        print("This contact will have their birthdays in this and next months:")
        if remind:
            print(tabulate(remind, headers=["Id","first name","last name","middle name","phone","birthday date"]))

    connection.commit()
    connection.close()
开发者ID:seniorivn,项目名称:python_contact_book,代码行数:70,代码来源:contactbook.py

示例3: test_add

# 需要导入模块: from contact import Contact [as 别名]
# 或者: from contact.Contact import add [as 别名]
 def test_add(self):
     contact = randomContact()
     self.added.append(contact)
     added, phoneexist, comment = Contact.add(contact,self.c, ())
     self.assertTrue(added)
开发者ID:seniorivn,项目名称:python_contact_book,代码行数:7,代码来源:test.py


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