本文整理汇总了Python中sys.stdout.write函数的典型用法代码示例。如果您正苦于以下问题:Python write函数的具体用法?Python write怎么用?Python write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write函数的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: refresh_articles
def refresh_articles(articles, feeds, urls):
for author, feed_urls in feeds.items():
articles[author] = []
relevant_urls = [url for url in feed_urls
if url in urls]
for url in relevant_urls:
stdout.write('parsing feed at %s.\n' % url)
feed = feedparser.parse(urls[url]['data'])
for entry in feed['entries']:
updated = entry.get('updated_parsed')
updated = date(year=updated.tm_year,
month=updated.tm_mon,
day=updated.tm_mday)
content = entry.get('content', '')
summary = entry.get('summary', '')
summary_detail = entry.get('summary_detail', {})
if not content:
if not (summary_detail and
summary_detail.get('value')):
if not summary:
pass
else:
content = [{'type': 'text/plain',
'value': summary}]
else:
content = [summary_detail]
if content:
article = {'url': entry.get('link'),
'title': entry.get('title'),
'pub_date': updated,
'content': content}
articles[author].append(article)
开发者ID:toolness,项目名称:daily-edition,代码行数:32,代码来源:publish_edition.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: _windows_shell
def _windows_shell(self, chan):
import threading
stdout.write("Line-buffered terminal emulation. Press F6 or ^Z to send EOF.\r\n\r\n")
def writeall(sock):
while True:
data = sock.recv(256)
if not data:
stdout.write("\r\n*** EOF ***\r\n\r\n")
stdout.flush()
break
stdout.write(data)
stdout.flush()
writer = threading.Thread(target=writeall, args=(chan,))
writer.start()
try:
while True:
d = stdin.read(1)
if not d:
break
chan.send(d)
except EOFError:
# user hit ^Z or F6
pass
开发者ID:roadlabs,项目名称:buildozer,代码行数:27,代码来源:__init__.py
示例5: main
def main():
if len(argv) >= 2:
out = open(argv[1], 'a')
else:
out = stdout
fmt1 = "{0:<16s} {1:<7s} {2:<7s} {3:<7s}\n"
fmt2 = "{0:<16s} {1:7d} {2:7d} {3:6.2f}%\n"
underlines = "---------------- ------- ------- -------".split()
out.write(fmt1.format(*"File Lines Covered Percent".split()))
out.write(fmt1.format(*underlines))
total_lines, total_covered = 0, 0
for percent, file, lines in sorted(coverage()):
covered = int(round(lines * percent / 100))
total_lines += lines
total_covered += covered
out.write(fmt2.format(file, lines, covered, percent))
out.write(fmt1.format(*underlines))
if total_lines == 0:
total_percent = 100.0
else:
total_percent = 100.0 * total_covered / total_lines
summary = fmt2.format("COVERAGE TOTAL", total_lines, total_covered,
total_percent)
out.write(summary)
if out != stdout:
stdout.write(summary)
开发者ID:datafueled,项目名称:memory-pool-system,代码行数:26,代码来源:gcovfmt.py
示例6: waitServe
def waitServe(servert):
""" Small function used to wait for a _serve thread to receive
a GET request. See _serve for more information.
servert should be a running thread.
"""
timeout = 10
status = False
try:
while servert.is_alive() and timeout > 0:
stdout.flush()
stdout.write("\r\033[32m [%s] Waiting for remote server to "
"download file [%ds]" % (utility.timestamp(), timeout))
sleep(1.0)
timeout -= 1
except:
timeout = 0
if timeout is not 10:
print ''
if timeout is 0:
utility.Msg("Remote server failed to retrieve file.", LOG.ERROR)
else:
status = True
return status
开发者ID:At9o11,项目名称:clusterd,代码行数:29,代码来源:deploy_utils.py
示例7: 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
示例8: add_column
def add_column(column_title, column_data):
# This is for the column TITLE - eg. Title could be Animal Names
for m in column_title:
length = len(m)
stdout.write('+' + '=' * (length + 2) + '+')
print('\r')
for m in column_title:
line_pos_right = ' |'
stdout.write('| ' + m + ' |')
print('\r')
for m in column_title:
stdout.write('+' + '=' * (length + 2) + '+')
print('\r')
# ----------------------------------------------------
# This is for the DATA of the column - eg. Label == Animal Names, the Data would be Sparkles, Hunter, etc.
for m in column_data:
this_length = len(m)
if this_length < length:
wanted_l = length - this_length
elif this_length > length:
wanted_l = this_length - length
stdout.write('| ' + m + ' ' * (wanted_l) + ' |')
print('\r')
stdout.write('+' + '-' * (length + 2) + '+')
开发者ID:mAzurkovic,项目名称:PyTbl,代码行数:30,代码来源:table.py
示例9: 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
示例10: log
def log(logtype, message):
func = inspect.currentframe().f_back
log_time = time.time()
if logtype != "ERROR":
stdout.write('[%s.%s %s, line:%03u]: %s\n' % (time.strftime('%H:%M:%S', time.localtime(log_time)), str(log_time % 1)[2:8], logtype, func.f_lineno, message))
else:
stderr.write('[%s.%s %s, line:%03u]: %s\n' % (time.strftime('%H:%M:%S', time.localtime(log_time)), str(log_time % 1)[2:8], logtype, func.f_lineno, message))
开发者ID:rabits,项目名称:rmusiccheck,代码行数:7,代码来源:rmusiccheck.py
示例11: 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
示例12: setup
def setup(self, type="constant", verbose=False):
self.type = type
self.verbose = verbose
if self.type is "constant":
# Set up the "data"
ny = 10
val, sigma = self.get_truepars()
self.true_pars = val
self.true_error = sigma
self.npars = 1
self.npoints = ny
self.y = zeros(ny, dtype="f8")
self.y[:] = val
self.y[:] += sigma * randn(ny)
self.yerr = zeros(ny, dtype="f8")
self.yerr[:] = sigma
self.ivar = 1.0 / self.yerr ** 2
# step sizes
self.step_sizes = sigma / sqrt(ny)
# self.parguess=val + 3*sigma*randn()
self.parguess = 0.0
if verbose:
stdout.write(' type: "constant"\n')
stdout.write(
" true_pars: %s\n npars: %s\n step_sizes: %s\n" % (self.true_pars, self.npars, self.step_sizes)
)
开发者ID:esheldon,项目名称:espy,代码行数:34,代码来源:mcmc.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: segment
def segment(text):
if not args.files and args.with_ids:
tid, text = text.split('\t', 1)
else:
tid = None
text_spans = rewrite_line_separators(
normal(text), pattern, short_sentence_length=args.bracket_spans
)
if tid is not None:
def write_ids(tid, sid):
stdout.write(tid)
stdout.write('\t')
stdout.write(str(sid))
stdout.write('\t')
last = '\n'
sid = 1
for span in text_spans:
if last == '\n' and span not in ('', '\n'):
write_ids(tid, sid)
sid += 1
stdout.write(span)
if span:
last = span
else:
for span in text_spans:
stdout.write(span)
开发者ID:WillemJan,项目名称:segtok,代码行数:32,代码来源:segmenter.py
示例16: 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
示例17: citation
def citation(print_out=True, short=False):
text = (short_citation_text if short else citation_text)
if print_out:
# Use a Python2/3 compatible form of printing:
from sys import stdout
stdout.write(text)
return text
开发者ID:Veterun,项目名称:mahotas,代码行数:7,代码来源:__init__.py
示例18: 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
示例19: 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
示例20: drawtopbar
def drawtopbar(width):
# First line:
mline("top", width)
# Second line:
stdout.write( colored("║", "yellow" ) )
beginwriting = ( int(width) / 2 ) - ( VERSION.__len__() ) - 2
i = 0
while i < int(width):
if i < beginwriting:
stdout.write(" ")
elif i == beginwriting:
stdout.write( colored( VERSION + " ║ " + OS, "yellow" ) )
i += VERSION.__len__() + OS.__len__() + 4
elif i >= int(width):
pass # This can probably be done nicer
else:
stdout.write(" ")
i += 1
stdout.write( colored("║", "yellow" ) )
# Third line:
mline("bot", width)
开发者ID:Brzoz,项目名称:SICK,代码行数:27,代码来源:draw.py
注:本文中的sys.stdout.write函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论