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


Python Console.get_string方法代码示例

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


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

示例1: edit_dvd

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def edit_dvd(db):
    title, identity = find_dvd(db, "edit")
    if title is None:
        return
    title = Console.get_string("Title", "title", title)
    if not title:
        return
    cursor = db.cursor()
    cursor.execute("SELECT dvds.year, dvds.duration, directors.name "
                   "FROM dvds, directors "
                   "WHERE dvds.director_id = directors.id AND "
                   "dvds.id=:id", dict(id=identity))
    year, duration, director = cursor.fetchone()
    director = Console.get_string("Director", "director", director)
    if not director:
        return
    year = Console.get_integer("Year", "year", year, 1896,
                               datetime.date.today().year)
    duration = Console.get_integer("Duration (minutes)", "minutes",
                                   duration, minimum=0, maximum=60*48)
    director_id = get_and_set_director(db, director)
    cursor.execute("UPDATE dvds SET title=:title, year=:year, "
                   "duration=:duration, director_id=:director_id "
                   "WHERE id=:identity", locals())
    db.commit()
开发者ID:178220709,项目名称:PyHello,代码行数:27,代码来源:dvds-sql.py

示例2: retrieve_car_details

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def retrieve_car_details(previous_license):
    license = Console.get_string("License", "license",
                                 previous_license) 
    if not license:
        return previous_license, None
    license = license.upper()
    ok, *data = handle_request("GET_CAR_DETAILS", license)
    if not ok:
        print(data[0])
        while True:
            start = Console.get_string("Start of license", "license")
            if not start:
                return previous_license, None
            start = start.upper()
            ok, *data = handle_request("GET_LICENSES_STARTING_WITH",
                                       start)
            if not data[0]:
                print("No licence starts with " + start)
                continue
            for i, license in enumerate(data[0]):
                print("({0}) {1}".format(i + 1, license))
            answer = Console.get_integer("Enter choice (0 to cancel)",
                                    minimum=0, maximum=len(data[0]))
            if answer == 0:
                return previous_license, None
            license = data[0][answer - 1]
            ok, *data = handle_request("GET_CAR_DETAILS", license)
            if not ok:
                print(data[0])
                return previous_license, None
            break
    return license, CarTuple(*data)
开发者ID:178220709,项目名称:PyHello,代码行数:34,代码来源:car_registration_ans.py

示例3: add_bookmark

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def add_bookmark(db):
    url = Console.get_string("URL", "URL")
    if not url:
        return
    if "://" not in url:
        url = "http://" + url
    name = Console.get_string("Name", "name")
    if not name:
        return
    db[name] = url
    db.sync()
开发者ID:178220709,项目名称:PyHello,代码行数:13,代码来源:bookmarks.py

示例4: add_dvd

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def add_dvd(db):
    title = Console.get_string("Title", "title")
    if not title:
        return
    director = Console.get_string("Director", "director")
    if not director:
        return
    year = Console.get_integer("Year", "year", minimum=1896,
                               maximum=datetime.date.today().year)
    duration = Console.get_integer("Duration (minutes)", "minutes",
                                   minimum=0, maximum=60*48)
    db[title] = (director, year, duration)
    db.sync()
开发者ID:178220709,项目名称:PyHello,代码行数:15,代码来源:dvds-dbm.py

示例5: edit_bookmark

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def edit_bookmark(db):
    name = find_bookmark(db, "edit")
    if name is None:
        return
    url = Console.get_string("URL", "URL", db[name])
    if not url:
        return
    if "://" not in url:
        url = "http://" + url
    new_name = Console.get_string("Name", "name", name)
    db[new_name] = url
    if new_name != name:
        del db[name]
    db.sync()
开发者ID:178220709,项目名称:PyHello,代码行数:16,代码来源:bookmarks.py

示例6: find_dvd

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def find_dvd(db, message):
    message = "(Start of) title to " + message
    cursor = db.cursor()
    while True:
        start = Console.get_string(message, "title")
        if not start:
            return (None, None)
        cursor.execute("SELECT title, id FROM dvds "
                       "WHERE title LIKE ? ORDER BY title",
                       (start + "%",))
        records = cursor.fetchall()
        if len(records) == 0:
            print("There are no dvds starting with", start)
            continue
        elif len(records) == 1:
            return records[0]
        elif len(records) > DISPLAY_LIMIT:
            print("Too many dvds ({0}) start with {1}; try entering "
                  "more of the title".format(len(records), start))
            continue
        else:
            for i, record in enumerate(records):
                print("{0}: {1}".format(i + 1, record[0]))
            which = Console.get_integer("Number (or 0 to cancel)",
                            "number", minimum=1, maximum=len(records))
            return records[which - 1] if which != 0 else (None, None)
开发者ID:178220709,项目名称:PyHello,代码行数:28,代码来源:dvds-sql.py

示例7: find_dvd

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def find_dvd(db, message):
    message = "(Start of) title to " + message
    while True:
        matches = []
        start = Console.get_string(message, "title")
        if not start:
            return None
        for title in db:
            if title.lower().startswith(start.lower()):
                matches.append(title)
        if len(matches) == 0:
            print("There are no dvds starting with", start)
            continue
        elif len(matches) == 1:
            return matches[0]
        elif len(matches) > DISPLAY_LIMIT:
            print("Too many dvds start with {0}; try entering "
                  "more of the title".format(start))
            continue
        else:
            matches = sorted(matches, key=str.lower)
            for i, match in enumerate(matches):
                print("{0}: {1}".format(i + 1, match))
            which = Console.get_integer("Number (or 0 to cancel)",
                            "number", minimum=1, maximum=len(matches))
            return matches[which - 1] if which != 0 else None
开发者ID:178220709,项目名称:PyHello,代码行数:28,代码来源:dvds-dbm.py

示例8: import_

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def import_(db):
    filename = Console.get_string("Import from", "filename")
    if not filename:
        return
    try:
        tree = xml.etree.ElementTree.parse(filename)
    except (EnvironmentError,
            xml.parsers.expat.ExpatError) as err:
        print("ERROR:", err)
        return

    cursor = db.cursor()
    cursor.execute("DELETE FROM directors")
    cursor.execute("DELETE FROM dvds")

    for element in tree.findall("dvd"):
        get_and_set_director(db, element.get("director"))
    for element in tree.findall("dvd"):
        try:
            year = int(element.get("year"))
            duration = int(element.get("duration"))
            title = element.text.strip()
            director_id = get_director_id(db, element.get("director"))
            cursor.execute("INSERT INTO dvds "
                           "(title, year, duration, director_id) "
                           "VALUES (?, ?, ?, ?)",
                           (title, year, duration, director_id))
        except ValueError as err:
            db.rollback()
            print("ERROR:", err)
            break
    else:
        db.commit()
    count = dvd_count(db)
    print("Imported {0} dvd{1}".format(count, Util.s(count)))
开发者ID:178220709,项目名称:PyHello,代码行数:37,代码来源:dvds-sql.py

示例9: new_registration

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def new_registration(previous_license):
    license = Console.get_string("License", "license")
    if not license:
        return previous_license
    license = license.upper()
    seats = Console.get_integer("Seats", "seats", 4, 0)
    if not (1 < seats < 10):
        return previous_license
    mileage = Console.get_integer("Mileage", "mileage", 0, 0)
    owner = Console.get_string("Owner", "owner")
    if not owner:
        return previous_license
    ok, *data = handle_request("NEW_REGISTRATION", license, seats, mileage, owner)
    if not ok:
        print(data[0])
    else:
        print("Car {0} successfully registered".format(license))
    return license
开发者ID:dronnix,项目名称:test,代码行数:20,代码来源:car_registration.py

示例10: add_dvd

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def add_dvd(db):
    title = Console.get_string("Title", "title")
    if not title:
        return
    director = Console.get_string("Director", "director")
    if not director:
        return
    year = Console.get_integer("Year", "year", minimum=1896,
                               maximum=datetime.date.today().year)
    duration = Console.get_integer("Duration (minutes)", "minutes",
                                   minimum=0, maximum=60*48)
    director_id = get_and_set_director(db, director)
    cursor = db.cursor()
    cursor.execute("INSERT INTO dvds "
                   "(title, year, duration, director_id) "
                   "VALUES (?, ?, ?, ?)",
                   (title, year, duration, director_id))
    db.commit()
开发者ID:178220709,项目名称:PyHello,代码行数:20,代码来源:dvds-sql.py

示例11: retrieve_car_details

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def retrieve_car_details(previous_license):
    license = Console.get_string("License", "license", previous_license)
    if not license:
        return previous_license, None
    license = license.upper()
    ok, *data = handle_request("GET_CAR_DETAILS", license)
    if not ok:
        print(data[0])
        return previous_license, None
    return license, CarTuple(*data)
开发者ID:dronnix,项目名称:test,代码行数:12,代码来源:car_registration.py

示例12: edit_dvd

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def edit_dvd(db):
    old_title = find_dvd(db, "edit")
    if old_title is None:
        return
    title = Console.get_string("Title", "title", old_title)
    if not title:
        return
    director, year, duration = db[old_title]
    director = Console.get_string("Director", "director", director)
    if not director:
        return
    year = Console.get_integer("Year", "year", year, 1896,
                               datetime.date.today().year)
    duration = Console.get_integer("Duration (minutes)", "minutes",
                                   duration, minimum=0, maximum=60*48)
    db[title] = (director, year, duration)
    if title != old_title:
        del db[old_title]
    db.sync()
开发者ID:178220709,项目名称:PyHello,代码行数:21,代码来源:dvds-dbm.py

示例13: new_registration

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def new_registration(previous_myLicense):
    myLicense = Console.get_string("License", "license") 
    if not myLicense:
        return previous_myLicense
    myLicense = myLicense.upper()
    seats = Console.get_integer("Seats", "seats", 4, 0)
    #if not (1 < seats < 10):
    #    return previous_myLicense
    mileage = Console.get_integer("Mileage", "mileage", 0, 0)
    owner = Console.get_string("Owner", "owner")
    #if not owner:
    #    return previous_myLicense
    # quito un *data y ponto data = 
    ok, data = handle_request("NEW_REGISTRATION", myLicense, seats,
                               mileage, owner)
    if not ok:
        print(data[0])
    else:
        print("Car {0} successfully registered".format(myLicense))
    return myLicense
开发者ID:dpeinado,项目名称:restec,代码行数:22,代码来源:car_registration.py

示例14: list_dvds

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def list_dvds(db):
    start = ""
    if len(db) > DISPLAY_LIMIT:
        start = Console.get_string("List those starting with "
                                   "[Enter=all]", "start")
    print()
    for title in sorted(db, key=str.lower):
        if not start or title.lower().startswith(start.lower()):
            director, year, duration = db[title]
            print("{title} ({year}) {duration} minute{0}, by "
                  "{director}".format(Util.s(duration), **locals()))
开发者ID:178220709,项目名称:PyHello,代码行数:13,代码来源:dvds-dbm.py

示例15: list_dvds

# 需要导入模块: import Console [as 别名]
# 或者: from Console import get_string [as 别名]
def list_dvds(db):
    start = ""
    if len(db) > DISPLAY_LIMIT:
        start = Console.get_string("List those starting with "
                                   "[Enter=all]", "start")
    print()
    for title in sorted(db, key=str.lower):
        if not start or title.lower().startswith(start.lower()):
            director, year, duration = db[title]
            print("{0} ({1}) {2} minute{3}, by {4}".format(
                  title, year, duration, Util.s(duration), director))
开发者ID:RedFelex,项目名称:First,代码行数:13,代码来源:dvds-dbm.py


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