本文整理汇总了Python中sys.stdout.flush函数的典型用法代码示例。如果您正苦于以下问题:Python flush函数的具体用法?Python flush怎么用?Python flush使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flush函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: out
def out(*text):
if isinstance(text, str):
stdout.write(text)
else:
for c in text:
stdout.write(str(c))
stdout.flush()
开发者ID:groboclown,项目名称:whimbrel,代码行数:7,代码来源:termcolor.py
示例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
开发者ID:U2Ft,项目名称:inbox-count,代码行数:27,代码来源:utils.py
示例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()
开发者ID:NuanceDev,项目名称:ndev-python-http-cli,代码行数:26,代码来源:asr_stream.py
示例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
开发者ID:cspollard,项目名称:DPlot,代码行数:35,代码来源:DUtils.py
示例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))
开发者ID:j0npau1,项目名称:pimento,代码行数:33,代码来源:pimento.py
示例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()
开发者ID:LipuFei,项目名称:gumby,代码行数:28,代码来源:log.py
示例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()
开发者ID:roadlabs,项目名称:buildozer,代码行数:7,代码来源:__init__.py
示例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)
开发者ID:Bartvds,项目名称:django-versatileimagefield,代码行数:29,代码来源:image_warmer.py
示例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()
开发者ID:Bartvds,项目名称:django-versatileimagefield,代码行数:30,代码来源:image_warmer.py
示例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()
开发者ID:andreask,项目名称:convert_jsontv,代码行数:26,代码来源:convert.py
示例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()
开发者ID:radjkarl,项目名称:fancyTools,代码行数:26,代码来源:statusBar.py
示例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()
开发者ID:kt10aan,项目名称:latex.tmbundle,代码行数:28,代码来源:texmate.py
示例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
开发者ID:RedmondSmyth,项目名称:spats,代码行数:29,代码来源:analyze_spats_targets.py
示例14: progress
def progress (itr):
t0 = time()
for i in itr:
stdout.write ('.')
stdout.flush ()
yield i
stdout.write ('[%.2f]\n' %(time()-t0))
开发者ID:funny-falcon,项目名称:pyvm,代码行数:7,代码来源:test_util.py
示例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)
开发者ID:devjeetr,项目名称:ufldl-exercises,代码行数:28,代码来源:test.py
示例16: get
def get(self, pfn, dest='.'):
""" Provides access to files stored inside connected the RSE.
:param pfn Physical file name of requested file
:param dest Name and path of the files when stored at the client
:raises DestinationNotAccessible, ServiceUnavailable, SourceNotFound
"""
path = self.path2pfn(pfn)
chunksize = 1024
try:
result = self.session.get(path, verify=False, stream=True, timeout=self.timeout, cert=self.cert)
if result and result.status_code in [200, ]:
length = int(result.headers['content-length'])
totnchunk = int(length / chunksize) + 1
progressbar_width = 100
stdout.write("[%s]\t 0/100" % (" " * progressbar_width))
nchunk = 0
f = open(dest, 'wb')
for chunk in result.iter_content(chunksize):
nchunk += 1
f.write(chunk)
percent = int(100 * nchunk / (float(totnchunk)))
stdout.write("\r[%s%s]\t %s/100" % ("+" * percent, "-" * (100 - percent), percent))
stdout.flush()
stdout.write('\n')
f.close()
elif result.status_code in [404, 403]:
raise exception.SourceNotFound()
else:
# catchall exception
raise exception.RucioException(result.status_code, result.text)
except requests.exceptions.ConnectionError, e:
raise exception.ServiceUnavailable(e)
开发者ID:pombredanne,项目名称:rucio,代码行数:34,代码来源:webdav.py
示例17: testSoftmaxMNIST
def testSoftmaxMNIST():
x_, y_ = getData("training_images.gz", "training_labels.gz")
N = 600
x = x_[0:N].reshape(N, 784).T/255.0
y = np.zeros((10, N))
for i in xrange(N):
y [y_[i][0]][i] = 1
#nn1 = SimpleNN(784, 800, 10, 100, 0.15, 0.4, False)
#nn2 = SimpleNN(784, 800, 10, 1, 0.15, 0.4, False)
nn3 = Softmax(784, 800, 1, 10, 0.15, 0, False)
nn4 = Softmax(784, 800, 10, 10, 0.35, 0, False)
#nn1.Train(x, y)
#nn2.Train(x, y)
nn3.Train(x, y)
nn4.Train(x, y)
N = 10000
x_, y_ = getData("test_images.gz", "test_labels.gz")
x = x_.reshape(N, 784).T/255.0
y = y_.T
correct = np.zeros((4, 1))
print "Testing"
startTime = time()
for i in xrange(N):
#h1 = nn1.Evaluate(np.tile(x.T[i].T, (1, 1)).T)
#h2 = nn2.Evaluate(np.tile(x.T[i].T, (1, 1)).T)
h3 = nn3.Evaluate(np.tile(x.T[i].T, (1, 1)).T)
h4 = nn4.Evaluate(np.tile(x.T[i].T, (1, 1)).T)
#if h1[y[0][i]][0] > 0.8:
# correct[0][0] += 1
#if h2[y[0][i]][0] > 0.8:
# correct[1][0] += 1
if h3[y[0][i]][0] > 0.8:
correct[2][0] += 1
if h4[y[0][i]][0] > 0.8:
correct[3][0] += 1
if(i > 0):
stdout.write("Testing %d/%d image. Time Elapsed: %ds. \r" % (i, N, time() - startTime))
stdout.flush()
stdout.write("\n")
#print "Accuracy 1: ", correct[0][0]/10000.0 * 100, "%"
#print "Accuracy 2: ", correct[1][0]/10000.0 * 100, "%"
print "Accuracy 3: ", correct[2][0]/10000.0 * 100, "%"
print "Accuracy 4: ", correct[3][0]/10000.0 * 100, "%"
开发者ID:devjeetr,项目名称:ufldl-exercises,代码行数:60,代码来源:test.py
示例18: main
def main():
for i, nugget in enumerate(gold_nugget_gen(),1):
stdout.write( "%d: %d\r" %(i, nugget))
stdout.flush()
if i == 15:
print "%d: %d" %(i, nugget)
break
开发者ID:ThomasZumsteg,项目名称:project-euler,代码行数:7,代码来源:problem_0137.py
示例19: _posix_shell
def _posix_shell(self, chan):
oldtty = termios.tcgetattr(stdin)
try:
# tty.setraw(stdin.fileno())
# tty.setcbreak(stdin.fileno())
chan.settimeout(0.0)
while True:
r, w, e = select([chan, stdin], [], [])
if chan in r:
try:
x = chan.recv(128)
if len(x) == 0:
print "\r\n*** EOF\r\n",
break
stdout.write(x)
stdout.flush()
# print len(x), repr(x)
except socket.timeout:
pass
if stdin in r:
x = stdin.read(1)
if len(x) == 0:
break
chan.sendall(x)
finally:
termios.tcsetattr(stdin, termios.TCSADRAIN, oldtty)
开发者ID:roadlabs,项目名称:buildozer,代码行数:27,代码来源:__init__.py
示例20: fill_peptide_parameters
def fill_peptide_parameters(protein_records):
print('Filling peptide parameters:')
protein_index = 1
for protein_record in protein_records:
print('Processing protein record #{0} of {1}:'.format(protein_index, len(protein_records)))
stdout.flush()
# 1. process received peptide records first
label = '{0:>25}: '.format('Received peptides ({0})'.format(len(protein_record.received_peptide_records)))
show_progress(label, 40, 0.0)
peptide_index = 1
for peptide_record in protein_record.received_peptide_records:
peptide_record.peptide_parameters = PeptideParameters(peptide_record.peptide.sequence)
show_progress(label, 40, peptide_index / len(protein_record.received_peptide_records))
peptide_index += 1
print()
# 2. process then missed peptide records
if len(protein_record.missed_peptide_records) == 0:
protein_index += 1
continue
label = '{0:>25}: '.format('Missed peptides ({0})'.format(len(protein_record.missed_peptide_records)))
show_progress(label, 40, 0.0)
peptide_index = 1
for peptide_record in protein_record.missed_peptide_records:
peptide_record.peptide_parameters = PeptideParameters(peptide_record.peptide.sequence)
show_progress(label, 40, peptide_index / len(protein_record.missed_peptide_records))
peptide_index += 1
print()
protein_index += 1
print()
print('Filling peptide parameters: done.')
开发者ID:zedrian,项目名称:shkoma,代码行数:33,代码来源:correlation.py
注:本文中的sys.stdout.flush函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论