本文整理汇总了Python中Console类的典型用法代码示例。如果您正苦于以下问题:Python Console类的具体用法?Python Console怎么用?Python Console使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Console类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __check__
def __check__(self, no):
if no < 0 or len(self.flist) <= no:
Console.print_temp("Invalid No.")
import time
time.sleep(1)
return False
return True
示例2: retrieve_car_details
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)
示例3: find_dvd
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)
示例4: find_dvd
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
示例5: edit_dvd
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()
示例6: remove_discrete_record
def remove_discrete_record(db):
identity = Console.get_integer("Delete record number", "id", minimum=0)
if id is None:
return
ans = Console.get_bool("Remove {0}?".format(identity), "no")
if ans:
cursor = db.cursor()
cursor.execute("DELETE FROM discrete_records WHERE id=?", (identity,))
db.commit()
示例7: add_bookmark
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()
示例8: add_dvd
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()
示例9: sendGameRequest
def sendGameRequest(connection: 'connection'):
s_output = connection[2]
s_input = connection[1]
string = 'AI_GAME'
send_to_server(s_output, string)
print('Client: ' + string)
serverReply = receive_from_server(s_input)
if serverReply == 'READY':
newGame = Console.new_game_state()
Console.print_board(newGame)
print('Server: ' +serverReply)
return newGame
else:
print('GameRequest: ERROR')
示例10: edit_bookmark
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()
示例11: interfaceConsole
def interfaceConsole(self):
"""
Some Comment
"""
lat = self.lat
lng = self.lng
zoom = self.zoom
size = self.size
if myFrame.infile is None:
tkMessageBox.showwarning("Open file", "Please Choose A KML file to Open")
infile = self.onOpen()
else:
infile = myFrame.infile
if myFrame.outfile is None:
tkMessageBox.showwarning("Write KML file", "Please Choose A KML file to write to")
outfile = self.saveFileKML()
else:
outfile = myFrame.outfile
if myFrame.outimage is None:
tkMessageBox.showwarning("Write Img file", "Please Choose an image file to write to")
outimage = self.saveFileImg()
else:
outimage = myFrame.outimage
# if ' ' in infile: infile = '"'+infile+'"'
# if ' ' in outimage: outimage = '"'+outimage+'"'
# if ' ' in outfile: outfile = '"'+outfile+'"'
sampleLine = """-wa -w {} -m {} -v -z {} -c {},{} -s {} {}""".format(outfile,
outimage, repr(zoom), repr(lat), repr(lng), repr(size), infile)
args = ['-wa', '-w', outfile, '-m', outimage, '-v', '-z', repr(zoom),
'-c', repr(lat)+','+ repr(lng), '-s', repr(size), infile]
if self.if_extract:
args = ['-h'] + args
# disable run button, to disallow too many running applications
self.run.config(state=DISABLED)
self.wd = waitDialog.WaitDialog(350, 100, myFrame.outimage)
self.wd.activate()
uiobserver = UiObserver(self)
imobserver = WaitObserver(self.wd)
urlobserver = WaitObserver(self.wd)
Console.interface(args, uiobserver, imobserver, urlobserver)
self.wd.end()
self.log("FINISHED", "\n" + str(self.div_string[0] * ((self.div_string[1]/len(self.div_string[0]))+1))[:self.div_string[1]] + "\n\n")
self.run.config(state=NORMAL)
示例12: main
def main():
functions = dict(a=add_record, l=list_records,
m=list_machines, r=remove_record, i=import_,
d=initialize_discrete_table, q=quit)
filename = os.path.join(os.path.dirname(__file__), "records.sdb")
db = None
try:
db = connect(filename)
action = ""
while True:
count = record_count(db)
print("\nRecords ({0})".format(os.path.basename(filename)))
if action != "l" and 1 <= count < DISPLAY_LIMIT:
list_records(db)
else:
print("{0} record{1}".format(count, Util.s(count)))
print()
menu = ("(A)dd (L)ist (M)achines (R)emove "
"(I)mport (D)iscretize (Q)uit"
if count else "(A)dd (I)mport (Q)uit")
valid = frozenset("almridq" if count else "aiq")
action = Console.get_menu_choice(menu, valid,
"l" if count else "a", True)
functions[action](db)
finally:
if db is not None:
db.close()
示例13: main
def main():
functions = dict(a=all_employee, r=list_report, m=list_manager, q=quit_app)
con = None
try:
# connect to hostName, userName, password, databaseName
con = mdb.connect("localhost", "testuser", "test623", "testdb")
cur = con.cursor()
initDB(con, cur)
print("\nManager and his/her reports:\n")
all_employee(cur)
action = ""
while True:
print()
menu = " (A)llEmployee List(R)eport List(M)anager (Q)uit"
action = Console.get_menu_choice(menu, "armq", "q", True)
functions[action](cur)
except mdb.Error as e:
print("Error %d: %s", e.args[0], e.args[1])
sys.exit(1)
finally:
if con is not None:
con.close()
示例14: main
def main():
functions = dict(a=add_dvd, e=edit_dvd, l=list_dvds,
d=list_directors, r=remove_dvd, i=import_,
x=export, q=quit)
filename = os.path.join(os.path.dirname(__file__), "dvds.sdb")
db = None
try:
db = connect(filename)
action = ""
while True:
count = dvd_count(db)
print("\nDVDs ({0})".format(os.path.basename(filename)))
if action != "l" and 1 <= count < DISPLAY_LIMIT:
list_dvds(db)
else:
print("{0} dvd{1}".format(count, Util.s(count)))
print()
menu = ("(A)dd (E)dit (L)ist (D)irectors (R)emove "
"(I)mport e(X)port (Q)uit"
if count else "(A)dd (I)mport (Q)uit")
valid = frozenset("adelrixq" if count else "aiq")
action = Console.get_menu_choice(menu, valid,
"l" if count else "a", True)
functions[action](db)
finally:
if db is not None:
db.close()
示例15: import_
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)))