本文整理汇总了Python中sys.stdout.flush函数的典型用法代码示例。如果您正苦于以下问题:Python flush函数的具体用法?Python flush怎么用?Python flush使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flush函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: out
def out(*text):
if isinstance(text, str):
stdout.write(text)
else:
for c in text:
stdout.write(str(c))
stdout.flush()
示例2: progress
def progress(reset=False):
global progress_state
max_dots = 6
indicator_length = max_dots + 2
if reset:
progress_state = ""
stdout.write("{}{}{}".format("\b" * indicator_length,
" " * indicator_length,
"\b" * indicator_length))
return True
if not progress_state:
progress_state = "[{}]".format("." + " " * (max_dots - 1))
else:
num_dots = progress_state.count(".")
if num_dots == max_dots:
num_dots == 0
else:
num_dots += 1
progress_state = "[{}]".format(("." * num_dots) + (" " * (max_dots - num_dots)))
stdout.write("\b" * indicator_length)
stdout.write(progress_state)
stdout.flush()
return True
示例3: __stream_audio_realtime
def __stream_audio_realtime(filepath, rate=44100):
total_chunks = 0
format = pyaudio.paInt16
channels = 1 if sys.platform == 'darwin' else 2
record_cap = 10 # seconds
p = pyaudio.PyAudio()
stream = p.open(format=format, channels=channels, rate=rate, input=True, frames_per_buffer=ASR.chunk_size)
print "o\t recording\t\t(Ctrl+C to stop)"
try:
desired_rate = float(desired_sample_rate) / rate # desired_sample_rate is an INT. convert to FLOAT for division.
for i in range(0, rate/ASR.chunk_size*record_cap):
data = stream.read(ASR.chunk_size)
_raw_data = numpy.fromstring(data, dtype=numpy.int16)
_resampled_data = resample(_raw_data, desired_rate, "sinc_best").astype(numpy.int16).tostring()
total_chunks += len(_resampled_data)
stdout.write("\r bytes sent: \t%d" % total_chunks)
stdout.flush()
yield _resampled_data
stdout.write("\n\n")
except KeyboardInterrupt:
pass
finally:
print "x\t done recording"
stream.stop_stream()
stream.close()
p.terminate()
示例4: fill_from_uncertains
def fill_from_uncertains(h, us):
if len(us) != h.GetNbinsX():
print "attempting to fill histogram with values list of different length. aborting."
stdout.flush()
return h
if h.InheritsFrom("TH3"):
for xBin in range(1, h.GetNbinsX()+1):
for yBin in range(1, h.GetNbinsY()+1):
for zBin in range(1, h.GetNbinsZ()+1):
u = us[xBin-1][yBin-1][zBin-1]
h.SetBinContent(xBin, yBin, zBin, u.x)
h.SetBinError(xBin, yBin, zBin, u.dx)
elif h.InheritsFrom("TH2"):
for xBin in range(1, h.GetNbinsX()+1):
for yBin in range(1, h.GetNbinsY()+1):
u = us[xBin-1][yBin-1]
h.SetBinContent(xBin, yBin, u.x)
h.SetBinError(xBin, yBin, u.dx)
elif h.InheritsFrom("TH1"):
for xBin in range(1, h.GetNbinsX()+1):
u = us[xBin-1]
h.SetBinContent(xBin, u.x)
h.SetBinError(xBin, u.dx)
else:
print "fill_from_uncertains(): attempting to fill an object that doesn't inherit from TH1. returning None."
stdout.flush()
return None
return h
示例5: record
def record(session):
starttime = time.time()
call ("clear")
print "Time-lapse recording started", time.strftime("%b %d %Y %I:%M:%S", time.localtime())
print "CTRL-C to stop\n"
print "Frames:\tTime Elapsed:\tLength @", session.fps, "FPS:"
print "----------------------------------------"
while True:
routinestart = time.time()
send_command(session)
session.framecount += 1
# This block uses the time module to format the elapsed time and final
# video time displayed into nice xx:xx:xx format. time.gmtime(n) will
# return the day, hour, minute, second, etc. calculated from the
# beginning of time. So for instance, time.gmtime(5000) would return a
# time object that would be equivalent to 5 seconds past the beginning
# of time. time.strftime then formats that into 00:00:05. time.gmtime
# does not provide actual milliseconds though, so we have to calculate
# those seperately and tack them on to the end when assigning the length
# variable. I'm sure this isn't the most elegant solution, so
# suggestions are welcome.
elapsed = time.strftime("%H:%M:%S", time.gmtime(time.time()-starttime))
vidsecs = float(session.framecount)/session.fps
vidmsecs = str("%02d" % ((vidsecs - int(vidsecs)) * 100))
length = time.strftime("%H:%M:%S.", time.gmtime(vidsecs)) + vidmsecs
stdout.write("\r%d\t%s\t%s" % (session.framecount, elapsed, length))
stdout.flush()
time.sleep(session.interval - (time.time() - routinestart))
示例6: setupLogging
def setupLogging():
config_file = path.join(environ['EXPERIMENT_DIR'], "logger.conf")
root = logging.getLogger()
# Wipe out any existing handlers
for handler in root.handlers:
print "WARNING! handler present before when calling setupLogging, removing handler: %s" % handler.name
root.removeHandler(handler)
if path.exists(config_file):
print "Found a logger.conf, using it."
stdout.flush()
logging.config.fileConfig(config_file)
else:
print "No logger.conf found."
stdout.flush()
root.setLevel(logging.INFO)
stdout_handler = logging.StreamHandler(stdout)
stdout_handler.setLevel(logging.INFO)
root.addHandler(stdout_handler)
stderr_handler = logging.StreamHandler(stderr)
stderr_handler.setLevel(logging.WARNING)
root.addHandler(stderr_handler)
observer = PythonLoggingObserver('root')
observer.start()
示例7: report_hook
def report_hook(index, blksize, size):
if size <= 0:
progression = "{0} bytes".format(index * blksize)
else:
progression = "{0:.2f}%".format(index * blksize * 100.0 / float(size))
print "- Download", progression, "\r",
stdout.flush()
示例8: warm
def warm(self):
"""
Returns a 2-tuple:
[0]: Number of images successfully pre-warmed
[1]: A list of paths on the storage class associated with the
VersatileImageField field being processed by `self` of
files that could not be successfully seeded.
"""
num_images_pre_warmed = 0
failed_to_create_image_path_list = []
total = self.queryset.count() * len(self.size_key_list)
for a, instance in enumerate(self.queryset, start=1):
for b, size_key in enumerate(self.size_key_list, start=1):
success, url_or_filepath = self._prewarm_versatileimagefield(
size_key,
reduce(getattr, self.image_attr.split("."), instance)
)
if success is True:
num_images_pre_warmed += 1
if self.verbose:
cli_progress_bar(num_images_pre_warmed, total)
else:
failed_to_create_image_path_list.append(url_or_filepath)
if a * b == total:
stdout.write('\n')
stdout.flush()
return (num_images_pre_warmed, failed_to_create_image_path_list)
示例9: cli_progress_bar
def cli_progress_bar(start, end, bar_length=50):
"""
Prints out a Yum-style progress bar (via sys.stdout.write).
`start`: The 'current' value of the progress bar.
`end`: The '100%' value of the progress bar.
`bar_length`: The size of the overall progress bar.
Example output with start=20, end=100, bar_length=50:
[###########----------------------------------------] 20/100 (100%)
Intended to be used in a loop. Example:
end = 100
for i in range(end):
cli_progress_bar(i, end)
Based on an implementation found here:
http://stackoverflow.com/a/13685020/1149774
"""
percent = float(start) / end
hashes = '#' * int(round(percent * bar_length))
spaces = '-' * (bar_length - len(hashes))
stdout.write(
"\r[{0}] {1}/{2} ({3}%)".format(
hashes + spaces,
start,
end,
int(round(percent * 100))
)
)
stdout.flush()
示例10: download_json_files
def download_json_files():
if not os.path.exists('/tmp/xmltv_convert/json'):
os.makedirs('/tmp/xmltv_convert/json')
page = urllib2.urlopen('http://json.xmltv.se/')
soup = BeautifulSoup(page)
soup.prettify()
for anchor in soup.findAll('a', href=True):
if anchor['href'] != '../':
try:
anchor_list = anchor['href'].split("_")
channel = anchor_list[0]
filedate = datetime.datetime.strptime(anchor_list[1][0:10], "%Y-%m-%d").date()
except IndexError:
filedate = datetime.datetime.today().date()
if filedate >= datetime.datetime.today().date():
if len(channels) == 0 or channel in channels or channel == "channels.js.gz":
stdout.write("Downloading http://xmltv.tvtab.la/json/%s " % anchor['href'])
f = urllib2.urlopen('http://xmltv.tvtab.la/json/%s' % anchor['href'])
data = f.read()
with open('/tmp/xmltv_convert/json/%s' % anchor['href'].replace('.gz', ''), 'w+ ') as outfile:
outfile.write(data)
stdout.write("Done!\n")
stdout.flush()
示例11: statusBar
def statusBar(step, total, bar_len=20, onlyReturn=False):
"""
print a ASCI-art statusbar of variable length e.g.showing 25%:
>>> step = 25
>>> total = 100
>>> print( statusBar(step, total, bar_len=20, onlyReturn=True) )
\r[=====o---------------]25%
as default onlyReturn is set to False
in this case the last printed line would be flushed every time when
the statusbar is called to create a the effect of one moving bar
"""
norm = 100.0 / total
step *= norm
step = int(step)
increment = 100 // bar_len
n = step // increment
m = bar_len - n
text = "\r[" + "=" * n + "o" + "-" * m + "]" + str(step) + "%"
if onlyReturn:
return text
stdout.write(text)
stdout.flush()
示例12: expand_name
def expand_name(filename, program='pdflatex'):
"""Get the expanded file name for a certain tex file.
Arguments:
filename
The name of the file we want to expand.
program
The name of the tex program for which we want to expand the
name of the file.
Returns: ``str``
Examples:
>>> expand_name('Tests/TeX/text.tex')
'./Tests/TeX/text.tex'
>>> expand_name('non_existent_file.tex')
''
"""
stdout.flush()
run_object = Popen("kpsewhich -progname='{}' {}".format(
program, shellquote(filename)), shell=True, stdout=PIPE)
return run_object.stdout.read().strip()
示例13: main
def main(argv=None):
params = Params()
try:
if argv is None:
argv = sys.argv
args,quiet = params.parse_options(argv)
params.check()
inputfile = args[0]
try:
adapter = args[1]
except IndexError:
adapter = "AGATCGGAAGAGCACACGTCTGAACTCCAGTCAC" #default (5' end of Illimuna multiplexing R2 adapter)
if quiet == False:
stdout.write("Using default sequence for adapter: {0}\n".format(adapter))
stdout.flush()
unique = analyze_unique(inputfile,quiet)
clip_min,error_rate = analyze_clip_min(inputfile,adapter,quiet)
return clip_min,unique,error_rate
except Usage, err:
print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
print >> sys.stderr, ""
return 2
示例14: progress
def progress (itr):
t0 = time()
for i in itr:
stdout.write ('.')
stdout.flush ()
yield i
stdout.write ('[%.2f]\n' %(time()-t0))
示例15: getData
def getData(imagePath, labelPath):
imageFile, labelFile = gzip.open(os.path.join(".", imagePath), 'rb'), gzip.open(os.path.join(".", labelPath), 'rb')
iMagic, iSize, rows, cols = struct.unpack('>IIII', imageFile.read(16))
lMagic, lSize = struct.unpack('>II', labelFile.read(8))
x = zeros((lSize, rows, cols), dtype=uint8)
y = zeros((lSize, 1), dtype=uint8)
count = 0
startTime = time()
for i in range(lSize):
for row in range(rows):
for col in range(cols):
x[i][row][col] = struct.unpack(">B", imageFile.read(1))[0]
y[i] = struct.unpack(">B", labelFile.read(1))[0]
count = count + 1
if count % 101 == 0:
stdout.write("Image: %d/%d. Time Elapsed: %ds \r" % (i, lSize, time() - startTime))
stdout.flush()
#if count > 600:
# break
stdout.write("\n")
return (x, y)