本文整理汇总了Python中sys.stderr.write函数的典型用法代码示例。如果您正苦于以下问题:Python write函数的具体用法?Python write怎么用?Python write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _print_progress
def _print_progress(self, iteration, n_iter,
cost=None, time_interval=10):
if self.print_progress > 0:
s = '\rIteration: %d/%d' % (iteration, n_iter)
if cost:
s += ' | Cost %.2f' % cost
if self.print_progress > 1:
if not hasattr(self, 'ela_str_'):
self.ela_str_ = '00:00:00'
if not iteration % time_interval:
ela_sec = time() - self._init_time
self.ela_str_ = self._to_hhmmss(ela_sec)
s += ' | Elapsed: %s' % self.ela_str_
if self.print_progress > 2:
if not hasattr(self, 'eta_str_'):
self.eta_str_ = '00:00:00'
if not iteration % time_interval:
eta_sec = ((ela_sec / float(iteration)) *
n_iter - ela_sec)
if eta_sec < 0.0:
eta_sec = 0.0
self.eta_str_ = self._to_hhmmss(eta_sec)
s += ' | ETA: %s' % self.eta_str_
stderr.write(s)
stderr.flush()
示例2: _validate_schema
def _validate_schema(self, corpus):
if self.schema_file is None:
if self.options.schema is None:
return True
self.schema = Schema(self.options.schema)
else:
self.schema = Schema('<internal>', self.schema_file)
print 'Schema validation:'
ignore = set()
if self.options.ignore is not None:
f = open(self.options.ignore)
for l in f:
ignore.add(l.strip())
f.close()
nerr = 0
nsil = 0
for msg in self.schema.check_corpus(corpus):
nerr += 1
if msg in ignore:
nsil += 1
else:
stderr.write(msg + '\n')
if nerr == 0:
print ' ok'
return True
if self.options.ignore is not None:
if nerr == nsil:
print ' ', str(nerr),'errors (all silenced)'
return True
print ' ', str(nerr), 'errors (', str(nsil), 'silenced)'
return False
print ' ', str(nerr), 'errors'
return False
示例3: plotSequences
def plotSequences(seq,filename):
from sys import stderr, argv
from os import popen
from os.path import basename
from re import sub;
import FWCore.ParameterSet.Config as cms
stderr.write("Writing plot to %s\n" % (filename,))
dot = popen("dot -Tpng > %s" % (filename,), "w")
dot.write("digraph G { \n rankdir=\"LR\" \n")
class visitor(object):
def __init__(self,seq,dot):
self._dot = dot
self._stack = []
self._seq = seq.label()
self._dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (self._seq,'orange',self._seq) + "\n" )
def seq(self, seq):
self._stack.append(self._seq)
self._seq = seq.label()
def enter(self,v):
if isinstance(v, cms.Sequence):
self._dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'orange',v.label()) + "\n" )
self.dep(v)
self.seq(v)
if isinstance(v, (cms.EDProducer, cms.EDFilter, cms.EDAnalyzer)):
self._dot.write( "%s [ shape=rect style=filled fillcolor=%s label=\"%s\" ]" % (v.label(),'green',v.label()) + "\n" )
self.dep(v)
def leave(self,v):
if isinstance(v, cms.Sequence):
self._seq = self._stack.pop()
def dep(self,v):
self._dot.write("%s -> %s" %(v.label(), self._seq) +"\n")
seq.visit(visitor(seq,dot))
dot.write("}\n")
dot.close()
示例4: main
def main():
DCT_H = 30
DCT_W = 40
a = 1
while a < len(argv):
if argv[a] == '-h':
DCT_H = int(argv[a+1])
i += 2
elif argv[a] == '-w':
DCT_W = int(argv[a+1])
i += 2
else:
stderr.write('Unknown option: %s\n' % argv[a])
return 1
for fname in stdin:
fname=fname.strip()
if len(fname) == 0: continue
f = basename(fname)[:3] # frame
us = basename(dirname(fname)).split('_')
u, s = us[0], us[1]
dct = reduce(lambda x,y: x+y,
GetDCT(fname)[:DCT_H,:DCT_W].tolist(), [])
odir = 'data/features/video/%s/%s' % (u, s)
if not exists(odir):
system('mkdir -p %s' % odir)
fdct = open('%s/%s.dct' % (odir, f), 'w')
for i in dct:
fdct.write('%f\n' % i)
fdct.close()
return 0
示例5: main
def main(args):
napalm = {"name": "Napalm", "func": Napalm, "flag_set": args.napalm}
mamont = {"name": "Mamont", "func": Mamont, "flag_set": args.mamont}
filewatcher = {"name": "FileWatcher", "func": Filewatcher, "flag_set": args.filewatcher}
filemare = {"name": "FileMare", "func": Filemare, "flag_set": args.filemare}
custom_functions = []
for routine in (napalm, mamont, filewatcher, filemare):
if(routine["flag_set"]):
custom_functions.append(routine)
# Process -fw, -fm, -ma, -na flags if they are set
if(len(custom_functions) > 0):
functions = custom_functions
else:
functions = (napalm, mamont, filewatcher, filemare)
# Start the scraping process
for function in functions:
try:
stderr.write("\t-=[ {0} ]=-\n".format(function["name"]))
stderr.flush()
function["func"](args).search()
except(KeyboardInterrupt, EOFError):
continue
stderr.write("\n")
stderr.flush()
示例6: result
def result():
global indent
indent -= 1
if midline:
stderr.write(" ")
else:
margin()
示例7: whichEC2Service
def whichEC2Service(env):
stderr.write("\x1b[2J\x1b[H")
if env == 'None':
import awstools as tool
e = tool.whichEnvironment() # optimize these two lines:
whichEC2Service(e) # whichEC2Service(tool.whichEnvironment())
else:
print 'what kind of thing might you be thinking about?:\n'
print ' 0) let me out, please'
print ' 1) query existing vpcs'
print ' 2) create a vpc'
print ' 3) modify a vpc'
print ' 4) delete a vpc'
print ''
m = raw_input('what\'s your pleasure?: ')
print ''
if m == '0':
exit()
elif m == '1':
queryEC2(env)
elif m == '2':
createEC2(env)
elif m == '3':
modifyEC2(env)
elif m == '4':
deleteEC2(env)
else:
print '\nuhm, no. let\'s try this again.... '
whichEC2Service(env)
示例8: _load_links
def _load_links(self):
""" Sorts supported and not supported links in two lists and returns them. """
try: # Process the arguments, either read links from file or directly
# from the command line with the -u/--url flag.
if self.args.file:
with open(self.args.file) as file_:
links = [url.decode("utf8").strip() for url in file_ if url.strip()]
else:
links = [url.decode("utf8").strip() for url in self.args.url if url.strip()]
# Remove duplicates
links = list(set(links))
except IOError:
stderr.write("Couldn't open input file, are you sure the path is correct?\n")
stderr.flush()
exit(1)
not_supported = []
supported = []
for link in links:
parse = urlparse.urlparse(link)
if(not parse.scheme):
link = "http://{0}".format(link)
if(self.is_supported(link) and parse.path):
supported.append(link)
else:
not_supported.append(link)
return supported, not_supported
示例9: unpacktype
def unpacktype(binstr, member, mtype):
offset = member[1]
size = member[2]
fmt = ''
if mtype == STR:
fmt = str(size) + 's'
elif mtype == INT:
fmt = 'I' if size == 4 else 'Q'
elif mtype == SHT:
fmt = 'H'
else:
calling_fxn = sys._getframe(1)
stderr.write("ERROR %s.%s tried to unpack the unknown type %d.\n" % (
callingclass(calling_fxn), calling_fxn.f_code.co_name, mtype))
return None
if struct.calcsize(fmt) != len(binstr[offset:size + offset]):
calling_fxn = sys._getframe(1)
stderr.write("ERROR %s.%s tried to unpack '%s' (fmt size: %d) from %d bytes.\n" % (
callingclass(calling_fxn), calling_fxn.f_code.co_name, fmt, struct.calcsize(fmt),
len(binstr[offset:size + offset])))
return None
return struct.unpack(fmt, binstr[offset:size + offset])[0]
示例10: reducer
def reducer(self, station, counts):
try:
if station[0] == 'error':
yield(station,sum(data))
return
self.increment_counter('MrJob Counters','reducer',1)
dic_TMIN={}
dic_TMAX={}
dic_PRCP={}
for vec in counts:
if vec[1]=='TMIN':
dic_TMIN[vec[0]]=vec[2]
elif vec[1]=='TMAX':
dic_TMAX[vec[0]]=vec[2]
else:
dic_PRCP[vec[0]]=vec[2]
validyear=[]
mean_MEAN=[]
mean_PRCP=[]
diff_MEAN=[]
for key in dic_TMIN:
if dic_TMAX.has_key(key) and dic_PRCP.has_key(key):
validyear.append(key)
mm=np.mean(np.array(dic_TMAX[key]))-np.mean(np.array(dic_TMIN[key]))
#mean_MEAN.append(mm/2.0)
#mean_PRCP.append(np.mean(np.array(dic_PRCP[key])))
diff_MEAN.append(mm)
if len(validyear)>0:
yield (station, np.mean(np.array(diff_MEAN)))
#else:
# yield (station, _)
except Exception, e:
#yield (('error','reducer', str(e)), 1)
stderr.write('Error in reducer')
示例11: doCombination
def doCombination(self):
## Contrary to Number-counting models, here each channel PDF already contains the nuisances
## So we just have to build the combined pdf
if len(self.DC.bins) > 1 or not self.options.forceNonSimPdf:
for (postfixIn,postfixOut) in [ ("","_s"), ("_bonly","_b") ]:
simPdf = ROOT.RooSimultaneous("model"+postfixOut, "model"+postfixOut, self.out.binCat) if self.options.noOptimizePdf else ROOT.RooSimultaneousOpt("model"+postfixOut, "model"+postfixOut, self.out.binCat)
for b in self.DC.bins:
pdfi = self.out.pdf("pdf_bin%s%s" % (b,postfixIn))
simPdf.addPdf(pdfi, b)
if len(self.DC.systs) and (not self.options.noOptimizePdf) and self.options.moreOptimizeSimPdf:
simPdf.addExtraConstraints(self.out.nuisPdfs)
if self.options.verbose:
stderr.write("Importing combined pdf %s\n" % simPdf.GetName()); stderr.flush()
self.out._import(simPdf)
if self.options.noBOnly: break
else:
self.out._import(self.out.pdf("pdf_bin%s" % self.DC.bins[0]).clone("model_s"), ROOT.RooFit.Silence())
if not self.options.noBOnly:
self.out._import(self.out.pdf("pdf_bin%s_bonly" % self.DC.bins[0]).clone("model_b"), ROOT.RooFit.Silence())
if self.options.fixpars:
pars = self.out.pdf("model_s").getParameters(self.out.obs)
iter = pars.createIterator()
while True:
arg = iter.Next()
if arg == None: break;
if arg.InheritsFrom("RooRealVar") and arg.GetName() != "r":
arg.setConstant(True);
示例12: grabber
def grabber():
while(True):
shuffle(BOARDS)
for b in BOARDS:
yield gen.Task(proc_board, b)
stderr.write('Grabber went to sleep\n')
yield gen.Task(IOLoop.instance().add_timeout, time.time() + 24 * 60 * 60)
示例13: featurize_and_uniq_triangles_stdin
def featurize_and_uniq_triangles_stdin(self):
tri_group = set()
tri_group_head = None
cnt = 0
for l in stdin:
cnt += 1
if cnt % 10000 == 0:
stderr.write('{0}\n'.format(cnt))
try:
l_ = l.decode('utf8').strip().split('\t')
this_tri = '\t'.join(l_[0:4])
if not tri_group_head:
tri_group_head = this_tri
tri_group.add(tuple(l_))
elif tri_group_head == this_tri:
tri_group.add(tuple(l_))
else:
if tri_group:
feat, pair = self.featurize_group(tri_group)
self.print_pair_with_features(pair, feat)
tri_group = set()
tri_group.add(tuple(l_))
tri_group_head = this_tri
except:
logging.exception('Exception at line: {0}'.format(l.strip()))
feat, pair = self.featurize_group(tri_group)
self.print_pair_with_features(pair, feat)
示例14: test_ewens
def test_ewens (kind, abd, test_failed):
'''
test estimation of theta by max likelihood with ewens formula
'''
t0 = time ()
test_ok=True
print ' Testing Ewens algorithm with BCI %s dataset' % kind
if kind == 'full':
wanted_theta = 34.962
wanted_lnl = 318.849
time_max = 0.05
elif kind == 'short':
wanted_theta = 33.302
wanted_lnl = 162.742
time_max = 0.05
abd.ewens_optimal_params()
abd.set_current_model ('ewens')
model = abd.get_model ('ewens')
print ' -> Optimal value of theta: %.3f' % abd.theta
if round (abd.theta, 3) != wanted_theta:
stderr.write ('\n test failed in ewens test (theta should have been %s)\n' %\
wanted_theta)
test_ok=False
print ' -> likelihood of theta: %.3f' % model.lnL
if round (model.lnL, 3) != wanted_lnl:
stderr.write ('\n test failed in ewens test (theta should have been %s)\n' %\
wanted_lnl)
test_ok=False
print '\n Elapsed time (should be < %s): %s sec\n' % (time_max, time() - t0)
if not test_ok:
test_failed.append ('etienne optimization')
return test_failed
示例15: residue
def residue( self, pos ):
''' return frag_idx of that pos '''
assert self._initialized
if pos in self.positions():
return self.__dict[ pos ]
else:
stderr.write("ERROR: %s is not in this pose\n" % pos )