本文整理汇总了Python中os.linesep.join函数的典型用法代码示例。如果您正苦于以下问题:Python join函数的具体用法?Python join怎么用?Python join使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了join函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inline_diff
def inline_diff(self):
"""Simple inline diff that just assumes that either the filename
has changed, or the text has been completely replaced."""
css_class = 'InlineDiff'
old_attr = self._parseField(self.oldValue,
filename=self.oldFilename)
new_attr = self._parseField(self.newValue,
filename=self.newFilename)
if old_attr:
old_fname = old_attr.pop(0)
else:
old_fname = None
if new_attr:
new_fname = new_attr.pop(0)
else:
new_fname = None
a = linesep.join(old_attr or [])
b = linesep.join(new_attr or [])
html = []
if old_fname != new_fname:
html.append(
self.inlinediff_fmt % ('%s FilenameDiff' % css_class,
old_fname, new_fname),
)
if a != b:
html.append(
self.inlinediff_fmt % (css_class, a, b),
)
if html:
return linesep.join(html)
示例2: check
def check(self):
'''
Check repository for unreferenced and missing files
'''
# Check if the repo is local
if not self.local:
raise ISError(u"Repository must be local")
local_files = set(listdir(self.config.path))
local_files.remove(self.config.dbname)
local_files.remove(self.config.lastname)
db_files = set(self.getallmd5())
# check missing files
arrow("Checking missing files")
missing_files = db_files - local_files
if len(missing_files) > 0:
out(linesep.join(missing_files))
# check unreferenced files
arrow("Checking unreferenced files")
unref_files = local_files - db_files
if len(unref_files) > 0:
out(linesep.join(unref_files))
# check corruption of local files
arrow("Checking corrupted files")
for f in local_files:
fo = PipeFile(join(self.config.path, f))
fo.consume()
fo.close()
if fo.md5 != f:
out(f)
示例3: print_layer_weights
def print_layer_weights(self, print_entire_array = False):
for i,l in enumerate(self.layers): # This is kind of hacky but will do for now.
if 'weights' in l:
if type(l['weights']) == n.ndarray:
print "%sLayer '%s' weights: %e [%e]" % (NL, l['name'], n.mean(n.abs(l['weights'])), n.mean(n.abs(l['weightsInc']))),
if print_entire_array:
n.set_printoptions(threshold=100)
print "weights.shape=%s" % (str(l['weights'].shape))
print "weights=[%s]" % (str(['weights'])),
print "weightsInc=[%s]" % (str(l['weightsInc'])),
elif type(l['weights']) == list:
print ""
print NL.join("Layer '%s' weights[%d]: %e [%e]" % (l['name'], i, n.mean(n.abs(w)), n.mean(n.abs(wi))) for i,(w,wi) in enumerate(zip(l['weights'],l['weightsInc']))),
if print_entire_array:
n.set_printoptions(threshold=100)
for i,(w,wi) in enumerate(zip(l['weights'],l['weightsInc'])):
print "weights.shape=%s" % (str(w.shape))
print "weights=[%s]" % (str(w)),
print "weightsInc=[%s]" % (str(wi)),
print "%sLayer '%s' biases: %e [%e]" % (NL, l['name'], n.mean(n.abs(l['biases'])), n.mean(n.abs(l['biasesInc']))),
if print_entire_array:
n.set_printoptions(threshold=100)
print "biases.shape=%s" % (str(l['biases'].shape))
print "biases=[%s]" % (str(l['biases'])),
print "biasesInc=[%s]" % (str(l['biasesInc'])),
print ""
示例4: print_test_results
def print_test_results(self):
print ""
print "======================Test output======================"
self.print_costs(self.test_outputs[-1])
print ""
print "-------------------------------------------------------",
for i, l in enumerate(self.layers): # This is kind of hacky but will do for now.
if "weights" in l:
if type(l["weights"]) == n.ndarray:
print "%sLayer '%s' weights: %e [%e]" % (
NL,
l["name"],
n.mean(n.abs(l["weights"])),
n.mean(n.abs(l["weightsInc"])),
),
elif type(l["weights"]) == list:
print ""
print NL.join(
"Layer '%s' weights[%d]: %e [%e]" % (l["name"], i, n.mean(n.abs(w)), n.mean(n.abs(wi)))
for i, (w, wi) in enumerate(zip(l["weights"], l["weightsInc"]))
),
print "%sLayer '%s' biases: %e [%e]" % (
NL,
l["name"],
n.mean(n.abs(l["biases"])),
n.mean(n.abs(l["biasesInc"])),
),
print ""
示例5: prompt_for_player
def prompt_for_player(self):
''' get player attributes from input,
initial player instance and
add player to the game
'''
available_colours = self.game.get_available_colours()
text = linesep.join(["choose type of player",
"0 - computer",
"1 - human"])
choice = self.validate_input(text, int, (0, 1))
if choice == 1:
name = self.validate_input("Enter name for player",
str, str_len=(1, 30))
available_options = range(len(available_colours))
if len(available_options) > 1:
# show available colours
options = ["{} - {}".format(index, colour)
for index, colour in
zip(available_options,
available_colours)]
text = "choose colour" + linesep
text += linesep.join(options)
choice = self.validate_input(text, int, available_options)
colour = available_colours.pop(choice)
else:
# only one colour left
colour = available_colours.pop()
player = Player(colour, name, self.prompt_choose_pawn)
elif choice == 0:
# automatically assign colours
colour = available_colours.pop()
player = Player(colour)
self.game.add_palyer(player)
示例6: discard
def discard():
if ''.join(lines):
if fragile:
raise ParseException('Unexpected text:%s%s' %
(linesep, linesep.join(lines)))
elif not quiet:
print >> stderr, 'Ignoring text:%s%s' % \
(linesep, linesep.join(lines))
示例7: __repr__
def __repr__(self):
#[str(self.delimiter),
outputs = sep.join([str(key)
+ ': ' + str(self.to_dict[key][DataStructure._INDEX_VALUE])
for key in self.to_dict])
inputs = sep.join([str(key)
+ ': ' + str(self.from_dict[key][DataStructure._INDEX_VALUE])
for key in self.from_dict])
return sep.join([self.delimiter,
'--Outputs--', outputs, '--Inputs--', inputs])
示例8: send_via_serial
def send_via_serial(self, vm, commands, action="send"):
"""
Connect to vm via netcat
pipe files for netcat are in specific directory on ESX datastore
@param vm: VirtualMachine instance
@param commands: list of commands
"""
commands_log = list()
conn = self.get_serial_connection_to_vyatta(vm)
logging.info('%s: connected' % vm.name_on_esx)
pattern = vm.ssh_pattern
timeout = CONFIGURE_TIMEOUT
err_log = ""
# Sends commands
for cmd in commands:
try:
conn.sendline(cmd)
result = conn.expect(pattern, timeout=timeout)
err_log +="\n======="
err_log +="\ncmd " + cmd
err_log +="\npattern " + str(pattern)
err_log +="\nresult= " + str(result)
err_log +="\nbefore " + conn.before
err_log +="\nafter " + conn.after
err_log +="\n======="
if result == 1:
# enter password for sudo
err_log +="\nGOT SUDO "
conn.sendline(vm.password)
conn.expect(pattern, timeout=timeout)
err_log +="\nbefore " + conn.before
err_log +="\nafter " + conn.after
err_log +="\n======="
commands_log.append('output: ' + conn.before + '\n')
if cmd.startswith('ls'):
logging.info("{}:packages which will be installed:{}"
"".format(vm.name_on_esx, conn.before))
except:
logging.error(
"{}:{}".format(vm.name_on_esx, linesep.join(commands_log)))
finally:
logging.debug(err_log)
conn.close()
log = linesep.join(commands_log)
if 'Commit failed' in log \
or 'Set failed' in log\
or 'dpkg: error' in log:
logging.error("{}:{}".format(vm.name_on_esx, log))
else:
logging.debug("{}:{}".format(vm.name_on_esx, log))
logging.info('{}: commands were sent'.format(vm.name_on_esx))
return vm.name_on_esx, log
示例9: write_cell_data
def write_cell_data(file_path, mesh, scalars={}, vectors={}, title="fvm2D"):
from os import linesep
with open(file_path, "w") as f:
write_header_pnts(f, mesh, title)
nbEdges = sum([len(boundary) for boundary in mesh.boundaries])
tot_len = sum([len(c) for c in mesh.cells]) + 2*nbEdges
ncells = len(mesh.cells) + nbEdges
f.write(linesep)
f.write("CELLS "+str(ncells)+" "+str(tot_len+ncells)+linesep)
for c in mesh.cells:
f.write(str(len(c))+" "+" ".join(map(str, c))+linesep)
for boundary in mesh.boundaries_points:
for e in boundary:
f.write(str(len(e))+" "+" ".join(map(str,e))+linesep)
f.write(linesep)
f.write("CELL_TYPES "+str(ncells)+linesep)
for c in mesh.cells:
if len(c) == 3:
f.write("5"+linesep)
elif len(c) == 4:
f.write("9"+linesep)
else:
f.write("7"+linesep)
f.write(linesep.join(["3"]*nbEdges))
f.write(linesep)
f.write("CELL_DATA "+str(ncells)+linesep)
for var in scalars:
field = scalars[var]
f.write("SCALARS "+var+" float 1"+linesep)
f.write("LOOKUP_TABLE default"+linesep)
f.write(linesep.join(map(str, field.data))+linesep)
for b in field.boundaries:
f.write(linesep.join(map(str, b.data))+linesep)
f.write(linesep)
for var in vectors:
xField = vectors[var][0]
yField = vectors[var][1]
f.write("VECTORS "+var+" float"+linesep)
for x, y in zip(xField.data, yField.data):
f.write(" ".join(map(str, [x, y, 0.0]))+linesep)
for xBs, yBs in zip(xField.boundaries, yField.boundaries):
for x,y in zip(xBs, yBs):
f.write(" ".join(map(str, [x, y, 0.0]))+linesep)
f.write(linesep)
示例10: __repr__
def __repr__(self):
r = ': ' + self.oid
r += ' [OBSOLETE]' if self.obsolete else ''
r += (linesep + ' Short name: ' + list_to_string(self.name)) if self.name else ''
r += (linesep + ' Description: ' + self.description) if self.description else ''
r += '<__desc__>'
r += (linesep + ' Extensions:' + linesep + linesep.join([' ' + s[0] + ': ' + list_to_string(s[1]) for s in self.extensions])) if self.extensions else ''
r += (linesep + ' Experimental:' + linesep + linesep.join([' ' + s[0] + ': ' + list_to_string(s[1]) for s in self.experimental])) if self.experimental else ''
r += (linesep + ' OidInfo: ' + str(self.oid_info)) if self.oid_info else ''
r += linesep
return r
示例11: __repr__
def __repr__(self):
tempstr = ""
if len(self.general) > 0:
tempstr = "General"
for key, value in self.general.items():
tempstr = linesep.join([tempstr, " " + key + " : " + value])
if len(self.subject) > 0:
tempstr = linesep.join([tempstr, "Subject"])
for key, value in self.subject.items():
tempstr = linesep.join([tempstr, " " + key + " : " + value])
return tempstr
示例12: print_network
def print_network(self):
print "-------------------------------------------------------",
for i,l in enumerate(self.layers): # This is kind of hacky but will do for now.
if 'weights' in l:
if type(l['weights']) == n.ndarray:
print "%sLayer '%s' weights: %e [%e]" % (NL, l['name'], n.mean(n.abs(l['weights'])), n.mean(n.abs(l['weightsInc']))),
elif type(l['weights']) == list:
print ""
print NL.join("Layer '%s' weights[%d]: %e [%e] (%e,%e)" % (l['name'], i, n.mean(n.abs(w)), n.mean(n.abs(wi)), n.min(w), n.max(w) ) for i,(w,wi) in enumerate(zip(l['weights'],l['weightsInc']))),
print "%sLayer '%s' biases: %e [%e]" % (NL, l['name'], n.mean(n.abs(l['biases'])), n.mean(n.abs(l['biasesInc']))),
print ""
示例13: header
def header(self, testname):
if self.rank == 0:
mf = len(makeTestData.slices)
mt = len(makeTestData.tsvars)
nf = len(self.spec_args['infiles'])
nt = mt if self.spec_args['timeseries'] is None else len(
self.spec_args['timeseries'])
hline = '-' * 100
hdrstr = [hline, '{}.{}:'.format(self.__class__.__name__, testname), '',
' specifier({}/{} infile(s), {}/{} TSV(s), ncfmt={ncfmt}, compression={compression}, meta1d={meta1d}, backend={backend})'.format(
nf, mf, nt, mt, **self.spec_args),
' s2srun {}'.format(' '.join(str(a) for a in self.runargs())), hline]
print eol.join(hdrstr)
示例14: print_test_results
def print_test_results(self):
print ""
print "======================Test output======================"
self.print_costs(self.test_outputs[-1])
print ""
print "-------------------------------------------------------"
for i,l in enumerate(self.layers): # This is kind of hacky but will do for now.
if 'weights' in l:
if type(l['weights']) == n.ndarray:
print "%sLayer '%s' weights: %e [%e] L2 norm/sqrt(size) %e" % (NL, l['name'], n.mean(n.abs(l['weights'])), n.mean(n.abs(l['weightsInc'])), n.linalg.norm(l['weights'])/sqrt(l['weights'].size))
elif type(l['weights']) == list:
print NL.join("Layer '%s' weights[%d]: %e [%e] L2 norm/sqrt(size) %e" % (l['name'], i, n.mean(n.abs(w)), n.mean(n.abs(wi)), n.linalg.norm(w)/sqrt(w.size)) for i,(w,wi) in enumerate(zip(l['weights'],l['weightsInc']))),
print "%sLayer '%s' biases: %e [%e]" % (NL, l['name'], n.mean(n.abs(l['biases'])), n.mean(n.abs(l['biasesInc'])))
print ""
示例15: print_test_results
def print_test_results(self):
print NL + "======================Test output======================"
self.print_costs(self.test_outputs[-1])
if not self.test_only:
print NL + "----------------------Averages-------------------------"
self.print_costs(self.aggregate_test_outputs(self.test_outputs[-len(self.test_batch_range):]))
print NL + "-------------------------------------------------------",
for name,val in sorted(self.layers.items(), key=lambda x: x[1]['id']): # This is kind of hacky but will do for now.
l = self.layers[name]
if 'weights' in l:
wscales = [(l['name'], i, n.mean(n.abs(w)), n.mean(n.abs(wi)), n.max(n.abs(w))) for i,(w,wi) in enumerate(zip(l['weights'],l['weightsInc']))]
print ""
print NL.join("Layer '%s' weights[%d]: %e [%e] [%e] max: %e " % (s[0], s[1], s[2], s[3], s[3]/s[2] if s[2] > 0 else 0, s[4]) for s in wscales),
print "%sLayer '%s' biases: %e [%e] max: %e " % (NL, l['name'], n.mean(n.abs(l['biases'])), n.mean(n.abs(l['biasesInc'])), n.max(n.abs(l['biases']))),
print ""